ldc-agis/database/factories/NewsFactory.php

41 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2023-12-19 15:09:12 +00:00
<?php
namespace Database\Factories;
use App\Enums\News\CategoryEnum;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class NewsFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
$title = fake()->sentence();
$publish_at = now()->subDays(rand(1, 30));
$unpublish_at = $publish_at->copy()->addDays(rand(1, 30));
$published = now() > $publish_at && now() < $unpublish_at ? true : false;
return [
'seo_title' => fake()->word(),
'seo_description' => fake()->text(160),
'title' => $title,
'slug' => Str::slug($title),
'category' => \collect(CategoryEnum::cases())->random(),
'picture_thumbnail_alt' => fake()->sentence(),
'picture_thumbnail_title' => fake()->sentence(),
'picture_alt' => fake()->sentence(),
'picture_title' => fake()->sentence(),
'subtitle' => fake()->sentence(),
'content' => \clean(\fake()->randomHtml(6, 7)),
'published' => $published,
'publish_at' => $publish_at,
'unpublish_at' => $unpublish_at,
];
}
}