feat: initial project setup with Laravel 12 and Filament v4
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SyncLog extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $table = 'sync_log';
|
||||
|
||||
protected $fillable = [
|
||||
'datetime',
|
||||
'ip',
|
||||
'user',
|
||||
'table_name',
|
||||
'action',
|
||||
'record_id',
|
||||
'changed_data',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'datetime' => 'datetime',
|
||||
'changed_data' => 'array',
|
||||
];
|
||||
|
||||
public static function lastSyncId(): int
|
||||
{
|
||||
return (int) static::where('action', 'synced')->max('id') ?: 0;
|
||||
}
|
||||
|
||||
public static function changesSince(int $since): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return static::where('id', '>', $since)
|
||||
->whereIn('action', ['created', 'updated', 'deleted'])
|
||||
->orderBy('id')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function markSynced(string $ip): static
|
||||
{
|
||||
return static::create([
|
||||
'datetime' => now(),
|
||||
'ip' => $ip,
|
||||
'user' => auth()->user()?->name ?? 'system',
|
||||
'table_name' => '',
|
||||
'action' => 'synced',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user