I will explain step by step tutorial laravel 8 seeder example. this example will help you laravel 8 database seeder example. it’s simple example of how to create seeder in laravel 8. it’s simple example of create seeder command in laravel 8.

You have lots of question what is seeder in laravel 8?, how to use seeder in laravel 8?, what is command to create seeder in laravel 8?, why we have to use seeder in laravel 8? that’s all i will example in this laravel 8 database seed tutorial.

Laravel introduce seeder for creating testing data and if you have small admin project then you can create admin user and also setting table default data.

Whenever you have admin project that don’t have register page then what you will do?, i mean you need to create at least one admin user. So basically he can login and access whole admin panel. But you don’t have register page on front end. you only have login page. So you can create one admin from database directly?, if yes then you have to always create new admin user from directly database when you create new setup of your project. But i will suggest you to create admin seeder so you can create admin user using laravel 8 seeder. You just fire on command to run seeder in laravel 8.

Same things, if you have default setting configuration then you can create setting seeder and add default configuration to your database table.

In this tutorial, i will show you how to create database seeder in laravel 8 and what is command to create seeder and how to run that seeder in laravel 8. so you have to just follow few step get how it’s done.

Laravel gives command to create seeder in laravel. so you can run following command to make seeder in laravel application.

Create Seeder Command:

php artisan make:seeder AdminUserSeeder

after run above command, it will create one file AdminUserSeeder.php on seeds folder. All seed classes are stored in the database/seeds directory.

Then you can write code of create admin user using model in laravel.

database/seeds/AdminUserSeeder.php

<?php

use Illuminate\Database\Seeder;
use App\Models\User;

class AdminUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        User::create([
            'name' => 'Hardik',
            'email' => 'admin@gmail.com',
            'password' => bcrypt('123456'),
        ]);
    }
}

#laravel #database #php #web-development

Laravel 8 Database Seeder Tutorial with Example
29.10 GEEK