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

Laravel 8 Seeders: Property [id] does not exist on this collection instance

I want to run seeders for tables users, courses and `episodes. Here is UserFactory: public function definition() { static $password; return [ 'name' => $this->faker->name, 'email' =>…
-1
votes
3 answers

Target class [Database\Seeders\MockNotification] does not exist in Laravel

i am using a seeder class to seed a table in the database
CoderTn
  • 985
  • 2
  • 22
  • 49
-1
votes
1 answer

Target class [DatabaseSeeder] does not exist

When I run php artisan migrate:fresh --seed I get the error: Target class [DatabaseSeeder] does not exist. I did the suggestions pointed in this link but not effect the same issue as in laravel 8 with seeding , i has this issue Target class…
PimD1988
  • 307
  • 5
  • 14
-1
votes
1 answer

Factory Class not found in laravel

Kindly assist, I don't understand why I'm getting the error Class 'Database\Factories\BookingFactory' not found after going through my code countless times! My BookingFactory.php
Alphy Gacheru
  • 489
  • 1
  • 9
  • 28
-1
votes
2 answers

I am creating user login management system with roles. I am getting error as, below when I run the command `$ php artisan db:seed`

I am creating user login management system with roles. I am getting error as, below when I run the command $ php artisan db:seed ErrorException file_get_contents(C:\xampp\htdocs\bizzcomputer\database/dumps/your_database.sql): failed to open stream:…
user14161797
-1
votes
1 answer

How can I add entries to a pivot table using for each in Laravel?

I need help with making a pivot table for all entires using for each in Laravel I have the following three tables Abilities ability_model Models +----------------+ +----------------------+ +-----------------+ …
-1
votes
1 answer

How do I fix the problem when I try to use seeder in laravel?

I am trying to add a super user in my laravel project. I have but the error occors. The use statement with non-compound name 'SuperAdminSeeder' has no effect", "E:\github\LARAVEL\Deal-Ocean\database\seeds\DatabaseSeeder.php",…
Backstreet Imrul
  • 102
  • 2
  • 15
-1
votes
1 answer

other value in Laravel form with seed database

I want to add other value as one of the options and show a new input field to write new value doesn't exist in options. This is the value of my options ON my Seed part. public function run() { Model::unguard(); //delete table records …
shrooq
  • 89
  • 1
  • 2
  • 8
-1
votes
1 answer

Table is existed but getting error SQLSTATE[42S02]: Base table or view not found: 1146 Table 'exyz.input_fields' doesn't exist

i'm trying to insert values from laravel seeder. All other tables data inserted but i'm stuck on input_fields table. Even it's working on my local Mamp server absoultely fine but when i try to run on Live server getting error but as i seen the table…
M.Awais
  • 31
  • 4
-1
votes
1 answer

How to create a master migration class that would call all your migration classes?

In Laravel the order in which you create your migration and seeders are essential. When these are run in artisan, if there are any foreign keys in a class(table), and one is executed before the one that is being referenced, the execution will stop,…
Marc DG
  • 51
  • 10
-1
votes
1 answer

Laravel Factories - How to save nested relationships

I was working with laravel factories and stuck with nested relation ships. For example a user may have many posts and a post has many comments. i was able to save posts with user by each() method but was not able to save comments with posts $users =…
Shehzad
  • 337
  • 4
  • 25
-1
votes
1 answer

Laravel Seeding with Faker DateTime

Okay so i am developing an application which receives some real time sensor readings from a device and stores it in a table inside the database. According to the use case the device will remain active for at least 8 hours each day and after a…
Badar Khan
  • 60
  • 1
  • 7
-1
votes
1 answer

mcrypt_decrypt not returning correct data only when used in Laravel seeding

We are using the built in Database Seeding in Laravel 5.3 under PHP 7.0 on Windows. Problem is that whenever we use mcrypt_encrypt to encrypt some data, the data we get back from mcrypt_decrypt is not the same as what we passed in. $data =…
Randar Puust
  • 363
  • 4
  • 14
-2
votes
2 answers

How to run a seeder file already runned file in laravel?

i am using Laravel seeder for inserting some data , it's already seeded without any errors now i added some extra data in the same file how can i run that same seeder file again...? file_name is `2022_05_13_110617_dummyDataSeeder.php` command i ran…
usersuser
  • 167
  • 12
-3
votes
1 answer

Can I create Seeder's object in migration in Laravel?

I would like to create one of my seeders' object in some migration in order to use some of its functions. Is it possible?
s7e0n5g1a
  • 47
  • 1
  • 7
1 2 3
21
22