MIF_E31230069/spk_kontrakan/app/Models/Admin.php

84 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Admin extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'role',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
/**
* ========== RELASI KONTRAKAN ==========
*/
/**
* Relasi: 1 Admin punya banyak Kontrakan
*/
public function kontrakans()
{
return $this->hasMany(Kontrakan::class);
}
/**
* Helper: Cek apakah admin adalah super_admin
*/
public function isSuperAdmin()
{
return $this->role === 'super_admin';
}
/**
* Helper: Cek apakah admin adalah admin biasa
*/
public function isAdmin()
{
return $this->role === 'admin';
}
/**
* Helper: Label human-readable untuk role admin.
*/
public function getRoleLabel()
{
return $this->role === 'super_admin' ? 'Super Admin' : 'Admin';
}
}