40 lines
699 B
PHP
40 lines
699 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Notifikasi extends Model
|
|
{
|
|
protected $table = 'notifikasi';
|
|
|
|
protected $fillable = [
|
|
'id_user',
|
|
'judul',
|
|
'pesan',
|
|
'tipe',
|
|
'data',
|
|
'is_read',
|
|
];
|
|
|
|
protected $casts = [
|
|
'data' => 'array',
|
|
'is_read' => 'boolean',
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'id_user', 'id');
|
|
}
|
|
|
|
public function scopeUnread($query)
|
|
{
|
|
return $query->where('is_read', false);
|
|
}
|
|
|
|
public function scopeForUser($query, int $userId)
|
|
{
|
|
return $query->where('id_user', $userId);
|
|
}
|
|
}
|