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
0
votes
1 answer

Pivot Table Seeding

I have two models Status and StatusCategory which have a belongToMany relationship. I have a pivot table status_status_category with two fields status_id and status_category_id I have also made these two fields the primary key. I have created model…
showFocus
  • 701
  • 2
  • 8
  • 21
0
votes
0 answers

How to increase migration and seeding speed in Laravel?

My database migrations and seeding speed is super slow. How to increase the speed of it? I'm frustrated because of this. It takes round about 20 mins for that. I have about 30 migrations and most data types are int,varchar and enum. I realized that…
user1994
  • 477
  • 6
  • 12
0
votes
0 answers

Error in using PHP fakers

I am trying to seed data as provided in this link https://github.com/fzaninotto/Faker. The tables are filled but but I got this error: $ php artisan db:seed Seeding: gamesSeeder Method Illuminate\Database\Query\Builder::issues does not…
Hanna
  • 539
  • 2
  • 9
  • 24
0
votes
1 answer

Seeding with two foreign key through relationship in laravel

I have tables users, posts, and comments, a user has many posts, each post has many comments (post_id in comments table), also a user has many comments but not fully required for anonymous user (user_id in comment table), code below seed each post…
Angga Ari Wijaya
  • 1,759
  • 1
  • 15
  • 31
0
votes
0 answers

Laravel 5. Error "VirtualAlloc() failed: [0x00000008]" when run "composer dump-autoload"

I get an error "Class does not exist" when trying to populate my DB by executing "php artisan seed:db". UserMoviesSeeder.php in the folder database/seeds has the following content:
0
votes
2 answers

One seeder class is working but other is not working, do you know why?

I have created two seeder classes 'UsersTableSeeder" and "Conferences TableSeeder". When the command "php artisan db:seed" is executed it appears: Seeding: UsersTableSeeder But the ConferenceTableSeeder don't work. Do you know why can…
user9289573
0
votes
1 answer

Factory and seeding of pivot table in Laravel

I have 3 tables Applicant,Skills and Applicant_skill. Here Applicant_skill is the pivot table. One Applicant has many Skills. I am trying to write factory like below. **ApplicantSkillFactory.php**
abu abu
  • 6,599
  • 19
  • 74
  • 131
0
votes
0 answers

Import Mysql functions file on laravel 5 seeder

I have some functions for Mysql on test.sql file. When I import this file on mysql from phpmyadmin everything is ok. But I want import it dynamically from Laravel Seeder. When I use this on my seeder, does not import it on my Mysql. public…
paranoid
  • 6,799
  • 19
  • 49
  • 86
0
votes
2 answers

How to track which seeders got applied in Laravel?

The obvious way to apply specific seeds rather than seeding everything is by using the --class flag: php artisan db:seed --class[=CLASS] Is there a way to track which seeders have been applied so far in Laravel (say, the same way you can track how…
abbood
  • 23,101
  • 16
  • 132
  • 246
0
votes
0 answers

could not find driver error in Laravel 5.5

I am facing below error while I am trying to run php artisan db:seed . I ran composer update and composer dump-autoload before. User.php use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use…
abu abu
  • 6,599
  • 19
  • 74
  • 131
0
votes
1 answer

Seed error in Laravel 5.5

I am facing seeding issue.My AddressessTableSeeder.php file is like below use Illuminate\Database\Seeder; class AddressessTableSeeder extends Seeder { public function run() { factory(App\Address::class, 50)->create()->each(function…
abu abu
  • 6,599
  • 19
  • 74
  • 131
0
votes
1 answer

Laravel: error when trying to change locale faker to he_IL

When i'm changing my faker locale to he_IL, I get this error: userName failed with the selected locale. Try a different locale or activate the "intl" PHP extension. How can i fix it, and what does it mean?
adir kandel
  • 725
  • 7
  • 9
0
votes
1 answer

Only one seed not working Laravel 5.5

all seeds are working but one throws exception Call to undefined method Illuminate\Support\Facades\Lang::setContainer() public function run() { DB::table('lang')->insert([ [ 'lang_name' => 'Русский' ], [ …
Viktor
  • 1,532
  • 6
  • 22
  • 61
0
votes
1 answer

Seeding a table with a primary key that is also a foreign key in Laravel

I have a Users table that acts as an abstract table for Engineers and Architects tables. Users [id (PK), first_name, last_name, role] where 'role' is either 'Engineer' or 'Architect' Engineers [id (PK/FK), experience, skill_set] where foreign 'id'…
syntax error
  • 15
  • 1
  • 8
0
votes
2 answers

Custom seeder in laravel 5.4

how can we make custom seeder in Laravel which can read the folder name and put into a specific column in database and the sub folder's name in the next column and finally the file name in the last?