forge/database/factories/ModFactory.php

60 lines
1.6 KiB
PHP
Raw Normal View History

2024-05-15 00:31:24 -04:00
<?php
namespace Database\Factories;
use App\Models\License;
use App\Models\Mod;
use Illuminate\Database\Eloquent\Factories\Factory;
2024-07-31 20:30:50 -04:00
use Illuminate\Support\Carbon;
2024-05-15 00:31:24 -04:00
use Illuminate\Support\Str;
use Random\RandomException;
2024-05-15 00:31:24 -04:00
class ModFactory extends Factory
{
protected $model = Mod::class;
/**
* @throws RandomException
*/
2024-05-15 00:31:24 -04:00
public function definition(): array
{
$name = fake()->catchPhrase();
2024-05-15 00:31:24 -04:00
return [
'name' => $name,
'slug' => Str::slug($name),
'teaser' => fake()->sentence(),
'description' => fake()->paragraphs(random_int(4, 20), true),
2024-05-15 00:31:24 -04:00
'license_id' => License::factory(),
'source_code_link' => fake()->url(),
'featured' => fake()->boolean(),
'contains_ai_content' => fake()->boolean(),
'contains_ads' => fake()->boolean(),
2024-07-31 20:30:50 -04:00
'published_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
'created_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
'updated_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
2024-05-15 00:31:24 -04:00
];
}
/**
* Indicate that the mod should be disabled.
*/
public function disabled(): static
{
return $this->state(fn (array $attributes) => [
'disabled' => true,
]);
}
2024-05-15 00:31:24 -04:00
/**
* Indicate that the mod should be soft-deleted.
*/
public function deleted(): static
{
return $this->state(fn (array $attributes) => [
'deleted_at' => now(),
]);
}
}