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
    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