e2f7d7f10f
- 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
37 lines
785 B
PHP
37 lines
785 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Vote extends Model
|
|
{
|
|
protected $fillable = [
|
|
'title', 'description', 'type',
|
|
'related_id', 'status', 'deadline', 'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'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');
|
|
}
|
|
|
|
public function items(): HasMany
|
|
{
|
|
return $this->hasMany(VoteItem::class);
|
|
}
|
|
}
|