Questions tagged [faker]

An extension or library used in certain programming languages or frameworks (namely Ruby or Yii2) for generating fake data for debug purposes and testing.

In Ruby, Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.

In Yii2, Faker can generate random strings (like name, address, phone number or anything), random numbers, keys or harshes as well as long sentences of fake text. It can be accessed in OOP style.

A PHP library is available for Faker that is used in some frameworks such as Laravel.

565 questions
38
votes
2 answers

FactoryGirl + Faker - same data being generated for every object in db seed data

I am using FactoryGirl and Faker to generate user objects in my seeds.rb file but for some reason the exact same user is being created and rake db:seed is failing because of an email uniqueness validation. Factory for users: #users.rb require…
sixty4bit
  • 6,262
  • 7
  • 27
  • 50
34
votes
4 answers

Laravel - Seeding Many-to-Many Relationship

I have a users table and a roles table that has a many-to-many relationship. These two tables are connected to a junction table called role_user. This is a model of the tables and its connections. Below are the Models in my Laravel…
Bilal Khawar
  • 351
  • 1
  • 3
  • 7
33
votes
4 answers

How to Generate Random String using Laravel Faker?

is there any way or method to generate fake string using laravel faker ? like in laravel we generate string upto 20 chars.. str_random(20);
Vishal
  • 421
  • 1
  • 6
  • 6
33
votes
4 answers

Faker.js random number between 2 values

This one is driving me a little mad, I'm sure it's simple but it doesn't seem to be documented anywhere. Im using Faker.js and the following to generate my random number: faker.random.number(); Works great, now if I want to do it between 2 numbers,…
K20GH
  • 4,944
  • 16
  • 60
  • 94
25
votes
4 answers

How to use Faker from Factory_boy

Factory_boy uses fake-factory (Faker) to generate random values, I would like to generate some random values in my Django tests using Faker directly. Factory_boy docs suggests using factory.Faker and its provider as : class…
marcanuy
  • 19,934
  • 8
  • 56
  • 109
25
votes
2 answers

NameError: uninitialized constant Faker

I am trying to run a simple bundle exec rake db:seed for my database in Rails 4. However, when running it, I get the following output: ********-C02MGBVJFD57:myapp ***********$ bundle exec rake db:seed Your Gemfile lists the gem factory_girl_rails…
user1072337
  • 11,489
  • 32
  • 105
  • 182
21
votes
4 answers

How to get future date in Faker

How do I get future dates with: https://github.com/fzaninotto/Faker#fakerproviderdatetime dateTime($max = 'now') i.e. what should the $max value be for datetime in the future
Angad Dubey
  • 4,307
  • 7
  • 26
  • 47
19
votes
2 answers

Laravel Faker - What's the difference between create and make

I have the following code: $this->actingAs(factory('App\User')->create()); $thread = factory('App\Thread')->make(); what is the difference between create() and make() and why is it not listed in the helper functions page in the Laravel…
Simon Suh
  • 8,581
  • 21
  • 75
  • 99
19
votes
2 answers

Populate Django database

I'm developing a Django application which stores user information like their address, phone number, name, etc. I've worked with PHP's Faker library and the seeder included with Laravel. I had been able to populate the database with fake data but now…
user3186459
  • 367
  • 1
  • 2
  • 11
17
votes
1 answer

How to use faker.js in typescript?

As in topic. I cannot handle it :/ I've installed npm i faker and also npm i @types/faker --save-dev my IDE found fakerStatic.name.findName() but browser not recognizes fakerStatic. import 'faker'; does not help.
piernik
  • 3,119
  • 3
  • 36
  • 71
17
votes
4 answers

How to implement your own Faker provider in Laravel

I want to create a custom provider for Faker in Laravel (e.g. one for a random building name). Where do I store the custom provider in my application and how do I use it?
carte
  • 983
  • 2
  • 9
  • 27
15
votes
2 answers

How to handle foreign key in FactoryGirl

I have a user model and a follower model, such that a user can have many followers. So in schema of follower model I have user_id column and a follower_by_user_id column. So in follower model a user can be followed by many followers. User id's are…
Geek_Akash
  • 189
  • 1
  • 11
13
votes
2 answers

Change faker gem phone number format

Is there a way to control the format of the Phone number generated by faker? When I call: Faker::PhoneNumber.cell_phone.to_i I end up getting the wrong value. I also would like to not have extensions.
rafamvc
  • 7,637
  • 4
  • 29
  • 34
12
votes
2 answers

Defining Laravel foreign keys with Model Factories, One to One & One to Many Relationships without creating unnecessary models

Recently I have been trying to seed my database using Laravel seeding through Model Factories and Faker. For simple schemas, it is just a breeze to have it working :). However, I have encountered several problems when working with complex DB schemas…
andcl
  • 2,473
  • 3
  • 25
  • 49
12
votes
1 answer

How to get a city inside a specific country with Faker

I'm working with the Faker extension in Laravel 5 to populate my database. I have "countries" and "Cities" tables so I called $faker->country but how can I get a city that is inside that country? I don't want "Bogotá" to belong to "EEUU".
Sredny M Casanova
  • 3,578
  • 10
  • 47
  • 93
1
2 3
37 38