Create project factory and seed data in laravel

Created at 23-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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.