File: /var/www/ipsremont-demo/database/seeds/DevicePartsSeeder.php
<?php
use App\Models\Device;
use App\Models\DeviceParts;
use App\Models\Part;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
class DevicePartsSeeder extends Seeder
{
public function run()
{
$devices = Device::get('id')->pluck('id')->toArray();
$parts = Part::get('id')->pluck('id')->toArray();
foreach ($parts as $partId) {
DeviceParts::create([
'device_id' => $devices[array_rand($devices)],
'part_id' => $partId,
'label' => Str::random(8),
'amount' => rand(0, 5)
]);
}
}
}