File: /home/armgroup/libs/database/factories/MenuFactory.php
<?php
namespace Database\Factories;
use App\Models\Menu;
use Illuminate\Database\Eloquent\Factories\Factory;
class MenuFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Menu::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'parent_id' => null,
'title' => $this->faker->sentence(2),
'url' => $this->faker->url,
'icon' => $this->faker->imageUrl(50, 50),
'sort_order' => rand(0, 100),
'status' => rand(0, 1),
];
}
public function parent()
{
return $this->state(function (array $attributes) {
return [
'parent_id' => Menu::query()->inRandomOrder()->first()->id,
];
});
}
}