72 lines
No EOL
1.9 KiB
PHP
72 lines
No EOL
1.9 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Trip;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Trip>
|
|
*/
|
|
class TripFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Trip::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$startDate = $this->faker->dateTimeBetween('now', '+1 year');
|
|
$endDate = $this->faker->dateTimeBetween($startDate, '+1 year');
|
|
|
|
return [
|
|
'name' => $this->faker->sentence(3),
|
|
'description' => $this->faker->optional()->paragraph(),
|
|
'start_date' => $this->faker->optional()->date('Y-m-d', $startDate),
|
|
'end_date' => $this->faker->optional()->date('Y-m-d', $endDate),
|
|
'created_by_user_id' => User::factory(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Indicate that the trip has no dates.
|
|
*/
|
|
public function withoutDates(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'start_date' => null,
|
|
'end_date' => null,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the trip is upcoming.
|
|
*/
|
|
public function upcoming(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'start_date' => now()->addDays(30)->format('Y-m-d'),
|
|
'end_date' => now()->addDays(37)->format('Y-m-d'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the trip is past.
|
|
*/
|
|
public function past(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'start_date' => now()->subDays(37)->format('Y-m-d'),
|
|
'end_date' => now()->subDays(30)->format('Y-m-d'),
|
|
]);
|
|
}
|
|
} |