Files
project-minnesota/database/factories/CategoryFactory.php

40 lines
853 B
PHP
Raw Normal View History

2024-05-15 12:28:03 +02:00
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Category;
use App\Models\Tag;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Category>
*/
class CategoryFactory extends Factory
{
/**
* Configure the model factory.
*/
public function configure(): static
{
return $this->afterCreating(function (Category $category) {
$randomTags = Tag::all()->random(rand(0,2));
$category->tags()->saveMany($randomTags);
});
}
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->sentence(2),
'cover' => './covers/image-'.rand(1,12).'-big.jpg',
];
}
}