51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Database\Factories;
|
||
|
|
|
||
|
|
use App\Enums\ActivityTypeEnum;
|
||
|
|
use App\Models\ActivityLog;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Support\Carbon;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @extends Factory<ActivityLog>
|
||
|
|
*/
|
||
|
|
class ActivityLogFactory extends Factory
|
||
|
|
{
|
||
|
|
protected $model = ActivityLog::class;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function definition(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'type' => fake()->randomElement(ActivityTypeEnum::cases()),
|
||
|
|
'message' => fake()->sentence(4),
|
||
|
|
'context' => null,
|
||
|
|
'subject_type' => null,
|
||
|
|
'subject_id' => null,
|
||
|
|
'logged_at' => now(),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function type(ActivityTypeEnum $type): static
|
||
|
|
{
|
||
|
|
return $this->state(['type' => $type]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function loggedAt(Carbon $loggedAt): static
|
||
|
|
{
|
||
|
|
return $this->state(['logged_at' => $loggedAt]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function for_subject(Model $subject): static
|
||
|
|
{
|
||
|
|
return $this->state([
|
||
|
|
'subject_type' => $subject->getMorphClass(),
|
||
|
|
'subject_id' => $subject->getKey(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|