How to Use Fake Factory in Laravel 11

How to Use Fake Factory in Laravel 11

Follow these steps:

Step 1

php artisan make:migration create_jobs_table

Step 2

example migration table

    public function up()
    {
        Schema::create('jobs', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('location');
            $table->string('type');
            $table->string('salary');
            $table->integer('hiring_client_id');
            $table->longText('description');
            $table->string('expected_duration');
            $table->string('skill_ids');
            $table->timestamps();
        });
    }

Step 3

php artisan migrate

Step 4

lets make model

php artisan make:model Jobs

Step 5

make factory

php artisan make:factory Jobs

Step 6

make seeder

php artisan make:seed JobsTableSeeder

Step 7

Start tinker

php artisan tinker

Step 8

final step

App\Models\Jobs::factory()->count(2)->create()

Step 9

run specific seeder

php artisan db:seed --class=JobsTableSeeder