step 1, 2 and 3 of the implementation plan
This commit is contained in:
78
app/Models/Log.php
Normal file
78
app/Models/Log.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
final class Log extends Model
|
||||
{
|
||||
/**
|
||||
* Disable the updated_at timestamp for append-only logs.
|
||||
*/
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
/**
|
||||
* Fillable attributes for mass assignment.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'session_id',
|
||||
'category_id',
|
||||
'action',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
/**
|
||||
* Cast attributes to specific types.
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'integer',
|
||||
'session_id' => 'integer',
|
||||
'category_id' => 'integer',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the model and prevent updates and deletes.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
self::updating(function (): bool {
|
||||
return false;
|
||||
});
|
||||
|
||||
self::deleting(function (): bool {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that performed the logged action.
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session associated with this log entry.
|
||||
*/
|
||||
public function session(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Session::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category associated with this log entry.
|
||||
*/
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user