ldc-tregalette/database/factories/NewsFactory.php

36 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2023-12-15 15:53:55 +00:00
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
2024-01-04 16:36:54 +00:00
use Illuminate\Support\Str;
2023-12-15 15:53:55 +00:00
class NewsFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
$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;
2024-01-04 16:36:54 +00:00
$title = fake()->unique()->slug(3);
2023-12-15 15:53:55 +00:00
return [
2024-01-04 16:36:54 +00:00
'title' => Str::of($title)->replace('-', ' ')->title(),
'slug' => Str::slug($title),
'seo_title' => fake()->sentence(),
'seo_description' => fake()->sentence(),
'picture_alt' => fake()->sentence(),
'picture_title' => fake()->sentence(),
'text' => \clean(\fake()->randomHtml(1, 1)),
'published' => $published,
'publish_at' => $publish_at,
'unpublish_at' => $unpublish_at,
2023-12-15 15:53:55 +00:00
];
}
}