Questions tagged [laravel-seeding]

Laravel includes a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. Seed classes may have any name you wish but probably should follow some sensible convention, such as UsersTableSeeder, etc. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.

Laravel includes a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. Seed classes may have any name you wish, but probably should follow some sensible convention, such as UsersTableSeeder, etc. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.

Example Database Seed Class

class DatabaseSeeder extends Seeder {

    public function run()
    {
        $this->call('UserTableSeeder');

        $this->command->info('User table seeded!');
    }

}

class UserTableSeeder extends Seeder {

    public function run()
    {
        DB::table('users')->delete();

        User::create(['email' => 'foo@bar.com']);
    }

}

To seed your database, you may use the db:seed command on the Artisan CLI:

php artisan db:seed

By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes. However, you may use the --class option to specify a specific seeder class to run individually:

php artisan db:seed --class=UserTableSeeder

You may also seed your database using the migrate:refresh command, which will also rollback and re-run all of your migrations:

php artisan migrate:refresh --seed
316 questions
1
vote
1 answer

Seeder for pivot table

I have pivot table taggable, it's table for Many To Many Polymorphic Relations (Tag and post) in Laravel: taggable_id - id of Post tag_id - id of Tag taggable type - location of post model (default value"App/Models/Posts/Post") is_search_term -…
Georg
  • 107
  • 1
  • 10
1
vote
1 answer

How write seeder in Laravel

I have table taggable, it's table for Many To Many Polymorphic Relations (Tag and post): taggable_id - id of Post tag_id - id of Tag taggable type - location of post model (default value"App/Models/Posts/Post") is_search_term - boolen (0 or 1) How…
Georg
  • 107
  • 1
  • 10
1
vote
1 answer

Laravel Seeding Issue

I'm having an issue regarding Laravel's Seeding... so I'm getting a [ErrorException] Illegal offset type from One of My seeds. I believe my issue is coming from the foreign key, from the other table that I'm using Below is My Model, My Table and My…
Greg Sithole
  • 145
  • 1
  • 2
  • 11
1
vote
2 answers

Laravel faker - loop to add records to simulate version control

I am using faker to seed my DB. $factory->define(App\Product::class, function (Faker\Generator $faker) { $campaign = factory(App\Campaign::class)->create(); $size= $faker->randomElement($array = array ('728x90','300x250','315x315',…
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
1
vote
1 answer

Faker with Laravel taking appending data from another factory

$factory->define(App\Client::class, function (Faker\Generator $faker) { static $password; $company_name = $faker->Company; return [ 'name' => $company_name, 'short_name' => substr($company_name, 0, 3), 'email'…
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
1
vote
1 answer

Seeding with Faker & four random words predefined

I use Faker for the first time with Laravel. I can not find anywhere to solve my problem. 2D "," 3D "or" common "with 20% chance for" web "," 2D "," 3D "and 40% For "common". Is it possible to do this with Faker? Thank you
Jeremy
  • 1,756
  • 3
  • 21
  • 45
1
vote
1 answer

LARAVEL 5.4 SQL "column not found" while seeding

I wonder if there is an "SQL cache" or something enabled by default in Laravel 5.4 I'm having this sql issue while running artisan db:seed : SQLSTATE[42703]: Undefined column: 7 ERROR: column « category » of relation « projects » doesn't exists …
C Taque
  • 997
  • 2
  • 15
  • 31
1
vote
1 answer

Array to string conversion when seeding a table

When trying to seed a table, it's showing an 'array to string conversion' error. This is the output of the error: [Illuminate\Database\QueryException] Array to string conversion (SQL: insert into `reviews` (`user_id`, `name`, `location`, `header`,…
user860511
1
vote
1 answer

How to reseed db without duplication - Laravel

I have this seeder class in my laravel 5.2 app : class UserTypesTableSeeder extends Seeder { public function run() { DB::table('user_types')->insert([ [ 'type' => 'patient', 'created_at' => Carbon::now(), 'updated_at' =>…
Rowayda Khayri
  • 489
  • 1
  • 9
  • 21
1
vote
1 answer

laravel factory model not found

im trying to create a new project with everything to know more about laravel, for now im creating models, migrations and seeds with factory and im running into this problem: Model User
syszen
  • 192
  • 3
  • 12
1
vote
1 answer

How can I seed data in Laravel from external data source?

So I am trying to seed data into my dB from an external api and not the default faker using the model factory in Laravel and I am stuck. Below is my code: $factory->define(\App\Models\State::class, function(){ $client = new Client(); …
Fatimah
  • 722
  • 7
  • 16
1
vote
0 answers

Seed a recursive table using factories in Laravel

I have a recursive table in my Laravel DB project that handles a dynamic menu. For testing purposes I want to seed that table with random elements. A random element of faker library will be okay for the menu name. The problem is how to generate the…
alexhoma
  • 342
  • 1
  • 7
  • 19
1
vote
1 answer

Laravel Missing Argument db:seed

I'm using Laravel. I'm creating my database and seed files. (not using Test Dummy) When I start the process of terminal and i got a Missing Argument errors. khazax@khz ~/Code/Laravel $ php artisan db:seed Seeded: UsersTableSeeder Seeded:…
Onur Kaya
  • 13
  • 3
1
vote
1 answer

laravel 5.2 seed not working

Migration
Jefsama
  • 553
  • 9
  • 29
1
vote
1 answer

How to run seeder in Laravel 5.1 with class parameter

I Use laravel 5.1 , I received "Class MySeederClass does not exist " when use --class in php artisan db::seed(like php artisan db::seed --class=MySeederClass) , but when I run this command without class parameter, every thing is ok, what is this…
atf.sgf
  • 458
  • 2
  • 4
  • 16