Hi,This post is focused on laravel 8 run all seeds. we will help you to give example of laravel 8 seeder all. i would like to share with you laravel 8 run all seeders. I’m going to show you about how to run all seeders in laravel 8.
Here, i will give you simple example of how to run all seeders file in laravel. you can easily use this example with laravel 6, laravel 7 and laravel 8 version.
let's see simple example:
you can use following command to all seeders in laravel application:
php artisan db:seed
you have to register all seeder in DatabaseSeeder.php file and that will run all seeders at a time, register as like bellow:
database/seeders/DatabaseSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
UserSeeder::class
AdminSeeder::class
]);
}
}
Your Admin Seeder as like bellow
database/seeders/AdminSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Admin;
class AdminSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Admin::create([
"name" => "Hardik Savani",
"email" => "admin@gmail.com",
"password" => bcrypt("123456")
]);
}
}
Your User Seeder as like bellow
database/seeders/UserSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
User::create([
"name" => "Hardik Savani",
"email" => "admin@gmail.com",
"password" => bcrypt("123456")
]);
}
}
you can use following command to run all seeder in laravel application:
php artisan db:seed
I hope it can help you...
Do you like below Tutorials ?
- How to Display Data in Angular 10?
- Angular 10 Routing Module Example Tutorial
- Angular 10 CRUD Operations with Web API Example
- Laravel 8 CRUD Operation Step By Step Tutorial
- Solved - Target class [ProductController] does not exist in Laravel 8
- Step by Step Form Validation in Laravel 8 Example
- Laravel 8 Image Upload with Preview Example
- Laravel 8 Multiple Images Upload with Preview Example