2017-10-07 03:18:36 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2021-06-10 13:18:00 -07:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2017-10-07 03:18:36 -07:00
|
|
|
use App\Models\Department;
|
2023-03-15 18:31:08 -07:00
|
|
|
use App\Models\Location;
|
2023-03-20 11:19:34 -07:00
|
|
|
use App\Models\User;
|
2021-06-10 13:15:52 -07:00
|
|
|
use Illuminate\Database\Seeder;
|
2017-10-07 03:18:36 -07:00
|
|
|
|
|
|
|
class DepartmentSeeder extends Seeder
|
|
|
|
{
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
Department::truncate();
|
2023-03-15 18:31:08 -07:00
|
|
|
|
|
|
|
if (! Location::count()) {
|
|
|
|
$this->call(LocationSeeder::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
$locationIds = Location::all()->pluck('id');
|
|
|
|
|
2023-03-20 11:19:34 -07:00
|
|
|
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
|
|
|
|
|
|
|
Department::factory()->count(1)->hr()->create([
|
|
|
|
'location_id' => $locationIds->random(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $admin->id,
|
2023-03-20 11:19:34 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
Department::factory()->count(1)->engineering()->create([
|
|
|
|
'location_id' => $locationIds->random(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $admin->id,
|
2023-03-20 11:19:34 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
Department::factory()->count(1)->marketing()->create([
|
|
|
|
'location_id' => $locationIds->random(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $admin->id,
|
2023-03-20 11:19:34 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
Department::factory()->count(1)->client()->create([
|
|
|
|
'location_id' => $locationIds->random(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $admin->id,
|
2023-03-20 11:19:34 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
Department::factory()->count(1)->product()->create([
|
|
|
|
'location_id' => $locationIds->random(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $admin->id,
|
2023-03-20 11:19:34 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
Department::factory()->count(1)->silly()->create([
|
|
|
|
'location_id' => $locationIds->random(),
|
2024-09-17 14:16:41 -07:00
|
|
|
'created_by' => $admin->id,
|
2023-03-20 11:19:34 -07:00
|
|
|
]);
|
2017-10-07 03:18:36 -07:00
|
|
|
}
|
|
|
|
}
|