Top Menu

In this article will provide some of the most important example how to run multiple seeders in laravel 8. This post goes in detailed on how to run multiple seeder in laravel 8. This post goes in detailed on laravel run multiple seeders. you will learn laravel 8 run all seeds.

Here, i will give you simple example of how to run all seeders file in laravel. you can easily use this example with laravel.

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([
            CreateAdminUserSeeder::class,
            AboutPagesTableDataSeeder::class,
	    HomePagesTableDataSeeder::class,
	    ExperiancesTableDataSeeder::class,
	    PortfoliosTableDataSeeder::class,
	    // some seeders register here	
        ]);

    }
}

Your Create Admin User Seeder as like bellow

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
class CreateAdminUserSeeder extends Seeder{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $user = User::create([
            'name' => 'admin', 
            'email' => 'admin@gmail.com',
            'password' => bcrypt('123456')

        ]);
    }
}

Your Create AboutPages Seeder as like bellow

<?php
namespace Database\Seeders;
use App\Models\AboutPages;
use Illuminate\Database\Seeder;
class AboutPagesTableDataSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
         AboutPages::create([
            'name' =>"IT Expert",
            'lastname' =>'IT-Expert',
            'dob' =>"1986-01-14",
            'nationality' =>"Indian",
            'freelance' =>"Available",
            'whatsapp_number' =>"9451293997",
            'address' =>"Indian",
            'phone_number' =>"9451293997",
            'email' =>"itexpert97@gmail.com",
            'skype' =>"itexpert",
            'language' =>"English, Hindi, Urdu",
            'download_cv' =>"uploads/cv.pdf",
            'experiance' =>"7+ years",
            'complete_project' =>"97+",
            'happy_customer' =>"81+",
            'awards_won' =>"53+",
        ]);
    }
}

Your Create HomePages Seeder as like bellow

<?php
namespace Database\Seeders;
use App\Models\homepages;
use Illuminate\Database\Seeder;
class HomepagesTableDataSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        homepages::create([
            'profile_image' =>"uploads/2.jpg",
            'heading' =>'IT-Expert',
            'profession' =>"Sr. PHP Developer",
            'content' =>"I m a IT-EXPERT based web designer & front end developer focused on crafting clean & user friendly experiences, I am passionate about building excellent software that improves the lives of those around me.",
        ]);
    }
}

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Close