28 lines
No EOL
566 B
PHP
28 lines
No EOL
566 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Comment;
|
|
use App\Models\Post;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class CommentSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$posts = Post::all();
|
|
$users = User::all();
|
|
|
|
foreach ($posts as $post) {
|
|
Comment::factory()
|
|
->count(rand(2, 5))
|
|
->create([
|
|
'post_id' => $post->id,
|
|
'author_id' => $users->random()->id,
|
|
]);
|
|
}
|
|
}
|
|
}
|