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
2 answers

Laravel Dusk: Migrate and Seed Testing DB Once

Is it possible to run migration and seeding once and don't refresh the testing db between the test methods? I have couple of testing functions that depend on each other and I don't want to migrate and seed the database before and after each test in…
Learner
  • 611
  • 3
  • 12
  • 28
1
vote
1 answer

Problem with seeding user profile data in Laravel

I have users and user_profiles table. I am trying to seed user profiles data in user_profiles table but I get error "Undefined offset: 0" It is possible that the problem is in UserProfileSeeder.php where I call user object with user profile…
mrmar
  • 1,407
  • 3
  • 11
  • 26
1
vote
1 answer

Problem with seeding users and their profiles in Laravel

I have user seeder and user profile seeder. Currently when I seed my database I get one hundred and fifty users in users table and just four users with their profiles filled in user_profiles table. Now, I know that the problem is in getUsers()…
mrmar
  • 1,407
  • 3
  • 11
  • 26
1
vote
1 answer

Problems with roles in laravel

Please note: I am pretty new to laravel and programming in general. So I am working on setting up a role system on my laravel project and I followed a tutorial and did eveything the same. My problem is that when registering it should register a new…
svw055
  • 85
  • 7
1
vote
1 answer

How to use a custom list of values for a Laravel factory, maintaing order and still using the Faker facade?

I have a list of names $names = ['Adam','Beth,'Chancie','Dale', 'Edward']; etc.. That I want to use in a Laravel factory, or seeder, I don't know which one. Basically, I still want to use the Faker functionality for everything else, but provide my…
user-44651
  • 3,924
  • 6
  • 41
  • 87
1
vote
3 answers

Problem Seeding the database after using nwidart package in Laravel

I am creating a modular application in Laravel and have used a package called nwidart.I am also using Spatie package for Role and Permission based ACL. This works fine, I have created a seeder class inside my module called API using this command…
Pweb
  • 155
  • 1
  • 4
  • 18
1
vote
1 answer

Laravel 5.8 - read and execute a SQL file dumped from DBeaver, running into string formating issues, principally a � before the INSERT

I have a SQL dump via DBeaver that ends up looking like this, but with 200k+ rows in 10 row segments: INSERT INTO addresses…
Matt Larsuma
  • 1,456
  • 4
  • 20
  • 52
1
vote
3 answers

Undefined index: icon error , while running laravel seeder

This is my code: DB::beginTransaction(); for($i = 0; $i < count($privileges); $i++) { DB::table('prev_definition')->insert([ 'priv_title' => $privileges[$i]['priv_title'], 'priv_key' =>…
syed1234
  • 761
  • 5
  • 12
  • 30
1
vote
1 answer

It is ok to store real data in laravel seeder Class?

Is just a question about laravel seeding, if I want to make my app portable, it is a good practice to save app-work-essential data in DatabaseSeeder laravel class? If not? How could I do it?
gmoros-dev
  • 25
  • 5
1
vote
2 answers

PHP_EOL troubles in Laravel Seeder

I tried to run the following lines inside the run() function of a Laravel seeder. $numbers = <<
cespon
  • 5,630
  • 7
  • 33
  • 47
1
vote
1 answer

Laravel Seed with Relationship (Real Data)

I'm trying to seed my table with some data with a belongsTo relationship, but I don't know how I should handle this relationship. Can anybody tell me what a belongsTo relationship should look like with seeding real data? Seed file public function…
nahoj
  • 285
  • 1
  • 4
  • 16
1
vote
2 answers

Make Seeder for Specific Values

I'm using a seeder in Laravel. I have a table called nationalities that has two columns: id and name. I want to seed more than one record with specific unique values (German, French, etc.). NationalitySeeder.php use Illuminate\Database\Seeder; use…
John Deck
  • 787
  • 1
  • 12
  • 27
1
vote
2 answers

Why does exporting from Excel to Csv cause Laravel Seeder to fail silently when using Flynsarmy csv seeder package?

I'm using this package: https://github.com/Flynsarmy/laravel-csv-seeder Flynsarmy Csv seeder works fine if I manually create a file and save it as a csv, then seed my database. Artisan responds with "Seeding: ProductsTableSeeder Database seeding…
1
vote
0 answers

Seeder already exists : Class LaravelSeeder does not exist

When the seeder is created by system A with command: php artisan make:seeder LaravelSeeder Then you can seed that seeder easily in system A with command: php artisan db:seed --class=LaravelSeeder But when the same seeder will be pushed and pulled in…
Brn.Rajoriya
  • 1,534
  • 2
  • 23
  • 35
1
vote
1 answer

Assigning permission to role while seeding - Entrust

Laravel 5.6.3 Entrust: 1.9 I am trying to seed only one row with this Seeder