62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
class Location extends Model
|
|
{
|
|
use LogsActivity;
|
|
|
|
protected $table = 'locations';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'status',
|
|
'description',
|
|
'enhancer_id',
|
|
];
|
|
|
|
public function subLocations()
|
|
{
|
|
return $this->hasMany(SubLocation::class, 'location_id', 'id');
|
|
}
|
|
|
|
public function issues()
|
|
{
|
|
return $this->hasMany(IssueManagement::class, 'location_id', 'id');
|
|
}
|
|
|
|
public function enhancer()
|
|
{
|
|
return $this->belongsTo(User::class, 'enhancer_id', 'id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['name', 'status', 'description', 'enhancer_id']) // kolom yang dicatat
|
|
->useLogName('location') // nama log
|
|
->logOnlyDirty(); // hanya log kalau ada perubahan
|
|
}
|
|
|
|
public function getDescriptionForEvent(string $eventName): string
|
|
{
|
|
switch ($eventName) {
|
|
case 'created':
|
|
$eventName = 'dibuat';
|
|
break;
|
|
case 'updated':
|
|
$eventName = 'diubah';
|
|
break;
|
|
case 'deleted':
|
|
$eventName = 'dihapus';
|
|
break;
|
|
}
|
|
|
|
return "Lokus '{$this->name}' telah {$eventName}";
|
|
}
|
|
}
|