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;
|
namespace App\Models;
|
||||||
|
|
||||||
use Database\Factories\UserFactory;
|
use Database\Factories\UserFactory;
|
||||||
|
use Filament\Models\Contracts\FilamentUser;
|
||||||
|
use Filament\Panel;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@@ -12,7 +14,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
|||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
|
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable implements FilamentUser
|
||||||
{
|
{
|
||||||
/** @use HasFactory<UserFactory> */
|
/** @use HasFactory<UserFactory> */
|
||||||
use HasFactory, Notifiable, HasRoles;
|
use HasFactory, Notifiable, HasRoles;
|
||||||
@@ -51,6 +53,11 @@ class User extends Authenticatable
|
|||||||
return $this->hasMany(CashRecord::class, 'created_by');
|
return $this->hasMany(CashRecord::class, 'created_by');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canAccessPanel(Panel $panel): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function canImpersonate(): bool
|
public function canImpersonate(): bool
|
||||||
{
|
{
|
||||||
return $this->hasRole('super_admin');
|
return $this->hasRole('super_admin');
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ class Vote extends Model
|
|||||||
'deadline' => 'datetime',
|
'deadline' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (Vote $vote) {
|
||||||
|
$vote->created_by ??= auth()->id();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function creator(): BelongsTo
|
public function creator(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'created_by');
|
return $this->belongsTo(User::class, 'created_by');
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class CashRecordObserver
|
|||||||
'related_id' => $record->id,
|
'related_id' => $record->id,
|
||||||
'status' => 'open',
|
'status' => 'open',
|
||||||
'deadline' => now()->addDays(3),
|
'deadline' => now()->addDays(3),
|
||||||
'created_by' => Auth::id(),
|
'created_by' => Auth::id() ?? $record->created_by,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
NotificationService::toRole('ketua',
|
NotificationService::toRole('ketua',
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Observers;
|
||||||
|
|
||||||
|
use App\Models\Vote;
|
||||||
|
use App\Services\NotificationService;
|
||||||
|
|
||||||
|
class VoteObserver
|
||||||
|
{
|
||||||
|
public function created(Vote $vote): void
|
||||||
|
{
|
||||||
|
NotificationService::toAll(
|
||||||
|
'Voting Baru Dibuat',
|
||||||
|
"Voting \"{$vote->title}\" telah dibuka. Silakan berikan suara Anda.",
|
||||||
|
'info',
|
||||||
|
route('filament.admin.resources.votes.index')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,11 @@ namespace App\Providers;
|
|||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
use App\Models\CashRecord;
|
use App\Models\CashRecord;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Vote;
|
||||||
use App\Observers\ActivityObserver;
|
use App\Observers\ActivityObserver;
|
||||||
use App\Observers\CashRecordObserver;
|
use App\Observers\CashRecordObserver;
|
||||||
use App\Observers\UserObserver;
|
use App\Observers\UserObserver;
|
||||||
|
use App\Observers\VoteObserver;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
@@ -17,5 +19,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
User::observe(UserObserver::class);
|
User::observe(UserObserver::class);
|
||||||
CashRecord::observe(CashRecordObserver::class);
|
CashRecord::observe(CashRecordObserver::class);
|
||||||
Activity::observe(ActivityObserver::class);
|
Activity::observe(ActivityObserver::class);
|
||||||
|
Vote::observe(VoteObserver::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,9 @@ class NotificationService
|
|||||||
if ($users->isEmpty()) return;
|
if ($users->isEmpty()) return;
|
||||||
self::send($users, $title, $body, $color, $url);
|
self::send($users, $title, $body, $color, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function toAll(string $title, string $body, string $color = 'info', ?string $url = null): void
|
||||||
|
{
|
||||||
|
self::send(User::all(), $title, $body, $color, $url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Regular → Executable
Generated
+6
-6
@@ -3338,16 +3338,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "livewire/livewire",
|
"name": "livewire/livewire",
|
||||||
"version": "v4.2.3",
|
"version": "v4.2.4",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/livewire/livewire.git",
|
"url": "https://github.com/livewire/livewire.git",
|
||||||
"reference": "d07bcb6fd04037a90ca5187b7857c7349a8e6d1e"
|
"reference": "7d0bfa46269b1ec186b8cdd38baffee5cc647d10"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/livewire/livewire/zipball/d07bcb6fd04037a90ca5187b7857c7349a8e6d1e",
|
"url": "https://api.github.com/repos/livewire/livewire/zipball/7d0bfa46269b1ec186b8cdd38baffee5cc647d10",
|
||||||
"reference": "d07bcb6fd04037a90ca5187b7857c7349a8e6d1e",
|
"reference": "7d0bfa46269b1ec186b8cdd38baffee5cc647d10",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -3402,7 +3402,7 @@
|
|||||||
"description": "A front-end framework for Laravel.",
|
"description": "A front-end framework for Laravel.",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/livewire/livewire/issues",
|
"issues": "https://github.com/livewire/livewire/issues",
|
||||||
"source": "https://github.com/livewire/livewire/tree/v4.2.3"
|
"source": "https://github.com/livewire/livewire/tree/v4.2.4"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -3410,7 +3410,7 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2026-03-30T22:17:37+00:00"
|
"time": "2026-04-02T20:48:35+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "monolog/monolog",
|
"name": "monolog/monolog",
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<?php phpinfo();
|
||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user