36 lines
994 B
PHP
36 lines
994 B
PHP
<?php
|
|
|
|
namespace Modules\User\Traits;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Modules\User\Models\ActivityLog;
|
|
|
|
trait HasActivityLogs
|
|
{
|
|
/**
|
|
* Create a new activity log.
|
|
*
|
|
* @param array $data
|
|
* @return \Illuminate\Database\Eloquent\Model
|
|
*/
|
|
public function createLog(array $data)
|
|
{
|
|
return $this->activityLogs()->create($data);
|
|
}
|
|
|
|
/**
|
|
* Define a polymorphic one-to-many relationship for activity logs.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
|
|
*/
|
|
public function activityLogs(): MorphMany
|
|
{
|
|
return $this->morphMany(ActivityLog::class, 'loggable')->latest();
|
|
}
|
|
|
|
// $estimate->customer->createLog([
|
|
// 'title' => 'Estimate Created',
|
|
// 'data' => "Estimate <span class='text-success'>{$estimate->estimate_code}</span> was created <span class='text-primary'>by</span> <span class='text-success'>" . auth()->user()->name . "</span>.",
|
|
// ]);
|
|
}
|