MIF_E31222307/app/Models/User.php

85 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'no_telp',
'password',
'role_id', // Added role_id to the fillable attributes
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Get the role associated with the user.
*/
public function role()
{
return $this->belongsTo(Role::class); // Defines the relationship to the Role model
}
/**
* Get the alert setting associated with the user.
*/
public function alertSetting()
{
return $this->hasOne(UserAlertSetting::class);
}
/**
* Get the notifications for the user.
*/
public function notifications()
{
return $this->hasMany(UserNotification::class);
}
/**
* Get unread notifications for the user.
*/
public function unreadNotifications()
{
return $this->notifications()->unread();
}
/**
* Get read notifications for the user.
*/
public function readNotifications()
{
return $this->notifications()->read();
}
}