2024-01-10 14:49:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Traits\Models;
|
|
|
|
|
|
2024-06-20 17:36:47 +02:00
|
|
|
use App\Models\ActivityLog as ActivityLogModel;
|
2026-09-25 16:25:31 +02:00
|
|
|
use App\Observers\ModelObserver;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2024-01-10 14:49:46 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If there is a static function in a trait (named boot[TraitName]),
|
|
|
|
|
* it will be executed as the boot() function would on an Eloquent model.
|
|
|
|
|
* Futhermore, event in the Model observer doesn't erase actual events in the model,
|
|
|
|
|
* but adds them.
|
|
|
|
|
*/
|
|
|
|
|
trait ActivityLog
|
|
|
|
|
{
|
|
|
|
|
public static function bootActivityLog(): void
|
|
|
|
|
{
|
|
|
|
|
static::observe(ModelObserver::class);
|
|
|
|
|
}
|
2024-03-28 13:04:37 +01:00
|
|
|
|
|
|
|
|
// * RELATIONS
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-20 17:36:47 +02:00
|
|
|
* Activities logs HasMany relationship.
|
2024-03-28 13:04:37 +01:00
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function activityLogs(): HasMany
|
2024-03-28 13:04:37 +01:00
|
|
|
{
|
2024-07-15 16:35:05 +02:00
|
|
|
return $this->hasMany(ActivityLogModel::class, 'model_id')->with('user');
|
2024-03-28 13:04:37 +01:00
|
|
|
}
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|