2025-12-30 15:03:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2026-01-16 17:36:37 +08:00
|
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
class Category extends Model
|
|
|
|
|
{
|
2026-01-16 17:36:37 +08:00
|
|
|
use HasFactory, LogsActivity;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'description',
|
|
|
|
|
'is_active',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'is_active' => 'boolean',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the products for the category.
|
|
|
|
|
*/
|
|
|
|
|
public function products(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Product::class);
|
|
|
|
|
}
|
2026-01-16 17:36:37 +08:00
|
|
|
|
|
|
|
|
public function getActivitylogOptions(): \Spatie\Activitylog\LogOptions
|
|
|
|
|
{
|
|
|
|
|
return \Spatie\Activitylog\LogOptions::defaults()
|
|
|
|
|
->logAll()
|
|
|
|
|
->logOnlyDirty()
|
|
|
|
|
->dontSubmitEmptyLogs();
|
|
|
|
|
}
|
2026-01-19 11:47:10 +08:00
|
|
|
|
|
|
|
|
public function tapActivity(\Spatie\Activitylog\Contracts\Activity $activity, string $eventName)
|
|
|
|
|
{
|
|
|
|
|
$properties = $activity->properties;
|
|
|
|
|
$attributes = $properties['attributes'] ?? [];
|
|
|
|
|
$attributes['name'] = $this->name;
|
|
|
|
|
$properties['attributes'] = $attributes;
|
|
|
|
|
$activity->properties = $properties;
|
|
|
|
|
}
|
2025-12-30 15:03:19 +08:00
|
|
|
}
|