Create project factory and seed data in laravel

Updated at 22-Jul-2021, By samar

Create project factory and seed data in laravel

In this article, we will see how to solve "Create project factory and seed data in laravel".

You can create the factory to generate the fake data and after that create a project seeder class and run that seeder class to seed dummy data in laravel
  • Create factory for project table

    php artisan make:factory ProjectFactory
    
     //database\factories\ProjectFactory.php
    public function definition()
    {
        return [
            'name' => $this->faker->word,
        ];
    }
    
  • Create dummy records for project table using seeder

    php artisan make:seeder ProjectSeeder
    //Import Project class
    use App\Models\Project;
    
    public function run()
    {
        $project = Project::factory()->count(5)->create();
    }
    
    php artisan db:seed --class=ProjectSeeder
    

Back to code snippet queries related laravel