fix: implementasi FilamentUser interface agar panel bisa diakses di production
- Tambah FilamentUser interface di User model - Tambah canAccessPanel() method - Tambah VoteObserver: broadcast notifikasi ke semua user saat vote baru - Tambah NotificationService::toAll() - Fix Vote model: auto-fill created_by via booted() - Fix CashRecordObserver: fallback created_by untuk Vote
This commit is contained in:
+8
-1
@@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -12,7 +14,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable, HasRoles;
|
||||
@@ -51,6 +53,11 @@ class User extends Authenticatable
|
||||
return $this->hasMany(CashRecord::class, 'created_by');
|
||||
}
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canImpersonate(): bool
|
||||
{
|
||||
return $this->hasRole('super_admin');
|
||||
|
||||
@@ -17,6 +17,13 @@ class Vote extends Model
|
||||
'deadline' => 'datetime',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Vote $vote) {
|
||||
$vote->created_by ??= auth()->id();
|
||||
});
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
|
||||
Reference in New Issue
Block a user