Skip to content

Commit

Permalink
Add Employer seeder
Browse files Browse the repository at this point in the history
Create Employer seeder scaffolding using make:seeder.

$ sail artisan make:seeder EmployerSeeder

   INFO  Seeder [database/seeders/EmployerSeeder.php] created successfully.

Build Employer seeder by using Employer factory.

Update Job seeder and Database seeder accordingly.

Now we can seed employers table individually.  At the same time seeding
all the tables works as before.
  • Loading branch information
sacren committed Jan 1, 2025
1 parent 1dcaefb commit f5e2fbd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function run(): void
'email' => '[email protected]',
]);

$this->call(EmployerSeeder::class);
$this->call(JobSeeder::class);
$this->call(TagSeeder::class);
$this->call(JobTagSeeder::class);
Expand Down
17 changes: 17 additions & 0 deletions database/seeders/EmployerSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Database\Seeders;

use App\Models\Employer;
use Illuminate\Database\Seeder;

class EmployerSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Employer::factory(10)->create();
}
}
4 changes: 1 addition & 3 deletions database/seeders/JobSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class JobSeeder extends Seeder
*/
public function run(): void
{
$employers = Employer::factory(10)->create();

Job::factory()->count(50)->create([
'employer_id' => fn () => $employers->random()->id,
'employer_id' => fn () => Employer::all()->random()->id,
]);
}
}

0 comments on commit f5e2fbd

Please sign in to comment.