fanatic/database/seeders/JoinedSeeder.php

49 lines
1 KiB
PHP
Raw Normal View History

2022-04-23 16:52:47 -07:00
<?php
namespace Database\Seeders;
use App\Models\Category;
use App\Models\Joined;
use Illuminate\Database\Seeder;
2022-04-26 18:43:36 -07:00
use Illuminate\Support\Facades\DB;
2022-04-23 16:52:47 -07:00
class JoinedSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
Joined::factory()
2022-04-26 18:43:36 -07:00
->count(50)
->create();
$pivots = [];
$cats = Category::inRandomOrder()->select('id')->get();
$i = 1;
while ($i <= 50) {
$pivots[] = [
'category_id' => $cats->random()->id,
'categorizable_id' => $i,
'categorizable_type' => 'joined',
];
++$i;
}
$i = 1;
while ($i <= rand(20, 100)) {
$pivots[] = [
'category_id' => $cats->random()->id,
'categorizable_id' => rand(1, 50),
'categorizable_type' => 'joined',
];
++$i;
}
DB::table('categorizables')->insert($pivots);
2022-04-23 16:52:47 -07:00
}
}