39 lines
898 B
PHP
39 lines
898 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class UserAlertSetting extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'is_enabled',
|
|
'alert_time',
|
|
'enabled_waktu_makan_ids'
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_enabled' => 'boolean',
|
|
'alert_time' => 'datetime',
|
|
'enabled_waktu_makan_ids' => 'array'
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function getEnabledWaktuMakanAttribute()
|
|
{
|
|
if (!$this->enabled_waktu_makan_ids) {
|
|
return WaktuMakan::where('is_active', true)->get();
|
|
}
|
|
return WaktuMakan::whereIn('id', $this->enabled_waktu_makan_ids)
|
|
->where('is_active', true)
|
|
->get();
|
|
}
|
|
}
|