28 lines
No EOL
603 B
PHP
28 lines
No EOL
603 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Post;
|
|
use App\Models\User;
|
|
use App\Models\Category;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class PostSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$authors = User::where('role', 'author')->get();
|
|
$categories = Category::all();
|
|
|
|
foreach ($authors as $author) {
|
|
Post::factory()
|
|
->count(3)
|
|
->create([
|
|
'author_id' => $author->id,
|
|
'category_id' => $categories->random()->id,
|
|
]);
|
|
}
|
|
}
|
|
}
|