forked from eatvio/eatvio-infra
'created seeder plan comments'
This commit is contained in:
62
database/seeders/PlanCommentSeeder.php
Executable file
62
database/seeders/PlanCommentSeeder.php
Executable file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Models\PlanComment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PlanCommentSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $table->id();
|
||||
// $table->bigInteger('user_id');
|
||||
// $table->bigInteger('plan_id');
|
||||
// $table->smallInteger('grade')->default(0);
|
||||
// $table->longText('body')->nullable();
|
||||
// $table->timestamps();
|
||||
//
|
||||
// return [
|
||||
// 'user_id' => User::count() > 0 ? function(User::)
|
||||
// 'plan_id'
|
||||
// 'body' => $this->faker->text(),
|
||||
// ];
|
||||
//
|
||||
// public function author()
|
||||
// {
|
||||
// return $this->belongsTo(User::class, 'user_id');
|
||||
// }
|
||||
|
||||
// public function plan()
|
||||
// {
|
||||
// return $this->belongsTo(Plan::class, 'plan_id');
|
||||
// }
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user