Tutorial by Examples

There are several ways to insert data: Using the DB Facade public function run() { DB::table('users') ->insert([ 'name' => 'Taylor', 'age' => 21 ]); } Via Instantiating a Model public function run() { $user = new User; $us...
Within your DatabaseSeeder class you are able to call other seeders $this->call(TestSeeder::class) This allows you to keep one file where you can easily find your seeders. Keep in mind that you need to pay attention to the order of your calls regarding foreign key constraints. You can't refe...
To create seeders, you may use the make:seeder Artisan command. All seeders generated will be placed in the database/seeds directory. $ php artisan make:seeder MoviesTableSeeder Generated seeders will contain one method: run. You may insert data into your database in this method. <?php us...
You may want to re-seed your database without affecting your previously created seeds. For this purpose, you can use firstOrCreate in your seeder: EmployeeType::firstOrCreate([ 'type' => 'manager', ]); Then you can seed the database: php artisan db:seed Later, if you want to add a...

Page 1 of 1