Files

25 lines
808 B
PHP
Raw Permalink Normal View History

2026-05-29 00:33:00 +03:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Activity extends Model
{
protected $fillable = ['user_id','type','subject_type','subject_id','data'];
protected $casts = ['data'=>'array'];
public function user(): BelongsTo { return $this->belongsTo(User::class); }
public function subject() { return $this->morphTo(); }
public static function log(int $userId, string $type, mixed $subject = null, array $data = []): self
{
return static::create([
'user_id' => $userId,
'type' => $type,
'subject_type' => $subject ? get_class($subject) : null,
'subject_id' => $subject?->id,
'data' => $data,
]);
}
}