forked from eatvio/eatvio-infra
38 lines
852 B
PHP
Executable File
38 lines
852 B
PHP
Executable File
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Plan;
|
|
use App\Models\PlanComment;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class PlanCommentSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
if (User::count() > 0 && Plan::count() > 0) {
|
|
$comments = PlanComment::factory()->count(5)->make();
|
|
|
|
$comments->each(function ($comment) {
|
|
$comment->author()->associate(
|
|
User::inRandomOrder()
|
|
->first()
|
|
->id
|
|
);
|
|
|
|
$comment->plan()->associate(
|
|
Plan::inRandomOrder()
|
|
->first()
|
|
->id
|
|
);
|
|
|
|
$comment->saveOrFail();
|
|
});
|
|
}
|
|
}
|
|
}
|