36 lines
868 B
PHP
36 lines
868 B
PHP
<?php
|
|
|
|
namespace App\Traits\Models;
|
|
|
|
use App\Observers\ModelObserver;
|
|
use App\Models\ActivityLog as ActivityLogModel;
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
// * RELATIONS
|
|
|
|
/**
|
|
* Activities logs One-to-many relationship.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function activityLogs(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
{
|
|
return $this->hasMany(ActivityLogModel::class, 'model_id');
|
|
}
|
|
}
|