ldc-volena/app/Traits/Models/ActivityLog.php

37 lines
911 B
PHP
Raw Permalink Normal View History

2023-11-13 11:56:06 +01:00
<?php
namespace App\Traits\Models;
use App\Observers\ModelObserver;
use App\Models\ActivityLog as ActivityLogModel;
2023-11-13 11:56:06 +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
{
/**
*
* @return void
*/
public static function bootActivityLog(): void
{
static::observe(ModelObserver::class);
}
2024-03-05 12:21:04 +01:00
// * RELATIONS
/**
* Activities logs One-to-many relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\ActivityLog, covariant static>
2024-03-05 12:21:04 +01:00
*/
public function activityLogs(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(ActivityLogModel::class, 'model_id');
2024-03-05 12:21:04 +01:00
}
2023-11-13 11:56:06 +01:00
}