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

Answers 2
  • Create factory for project table

    php artisan make:factory ProjectFactory
    
     //database\factories\ProjectFactory.php
    public function definition()
    {
        return [
            'name' => $this->faker->word,
        ];
    }
    
    0
  • 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
    
    0
  • Back to code snippet queries related laravel