*/ use HasFactory; use \Spatie\Activitylog\Traits\LogsActivity; protected $fillable = [ 'code', 'name', 'address', 'description', ]; public function getActivitylogOptions(): \Spatie\Activitylog\LogOptions { return \Spatie\Activitylog\LogOptions::defaults() ->logAll() ->logOnlyDirty() ->dontSubmitEmptyLogs(); } public function tapActivity(\Spatie\Activitylog\Contracts\Activity $activity, string $eventName) { $properties = $activity->properties; $attributes = $properties['attributes'] ?? []; // Always snapshot name $attributes['name'] = $this->name; $properties['attributes'] = $attributes; $activity->properties = $properties; } public function inventories(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Inventory::class); } public function purchaseOrders(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(PurchaseOrder::class); } public function products(): \Illuminate\Database\Eloquent\Relations\BelongsToMany { return $this->belongsToMany(Product::class, 'inventories') ->withPivot(['quantity', 'safety_stock', 'location']) ->withTimestamps(); } }