57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Enums\EquipmentCondition;
|
|
use App\Enums\UserRole;
|
|
use App\Models\Equipment;
|
|
use App\Models\EquipmentCategory;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class EquipmentSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$categories = EquipmentCategory::query()->get();
|
|
$clients = User::query()->where('role', UserRole::CLIENT)->get();
|
|
|
|
$names = [
|
|
'Ноутбук Dell Latitude',
|
|
'HP ProDesk',
|
|
'Cisco Router',
|
|
'Brother MFC Printer',
|
|
'Lenovo ThinkPad',
|
|
];
|
|
|
|
$conditions = array_map(fn (EquipmentCondition $case) => $case->value, EquipmentCondition::cases());
|
|
|
|
$notes = [
|
|
'Оборудование используется в штатном режиме.',
|
|
'Требуется периодическая профилактика.',
|
|
'Закреплено за пользователем в рамках эксплуатации.',
|
|
'Используется для выполнения рабочих задач.',
|
|
'Находится в исправном состоянии.',
|
|
];
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
$category = $categories->random();
|
|
$client = $clients->random();
|
|
|
|
Equipment::query()->updateOrCreate(
|
|
['inventory_number' => sprintf('INV-%04d', $i)],
|
|
[
|
|
'name' => $names[($i - 1) % count($names)].' '.$i,
|
|
'serial_number' => sprintf('SN-%08d', 10000000 + $i),
|
|
'category_id' => $category->id,
|
|
'client_id' => $client->id,
|
|
'purchase_date' => now()->subMonths(rand(6, 48))->toDateString(),
|
|
'warranty_until' => now()->addDays(rand(-90, 365))->toDateString(),
|
|
'condition' => $conditions[($i - 1) % count($conditions)],
|
|
'notes' => $notes[($i - 1) % count($notes)],
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|