first change
This commit is contained in:
35
Modules/User/app/Traits/HasActivityLogs.php
Normal file
35
Modules/User/app/Traits/HasActivityLogs.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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>.",
|
||||
// ]);
|
||||
}
|
Reference in New Issue
Block a user