93 lines
1.8 KiB
PHP
93 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Admin\AdminRole;
|
|
use App\Enums\Admin\AdminStatus;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User;
|
|
|
|
/**
|
|
* Class Admin
|
|
*
|
|
* @property int $id
|
|
* @property string $first_name
|
|
* @property string $last_name
|
|
* @property string $username
|
|
* @property string $email
|
|
* @property string $mobile
|
|
* @property string $password
|
|
* @property int|null $file_id
|
|
* @property int $role
|
|
* @property int $status
|
|
* @property Carbon|null $last_login_at
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @property string|null $deleted_at
|
|
*
|
|
* @property File|null $file
|
|
* @property Collection|Comment[] $comments
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class Admin extends User
|
|
{
|
|
use SoftDeletes;
|
|
protected $table = 'admins';
|
|
public static $snakeAttributes = false;
|
|
|
|
protected $casts = [
|
|
'file_id' => 'int',
|
|
'role' => AdminRole::class,
|
|
'status' => AdminStatus::class,
|
|
'last_login_at' => 'datetime'
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'first_name',
|
|
'last_name',
|
|
'username',
|
|
'email',
|
|
'mobile',
|
|
'password',
|
|
'file_id',
|
|
'role',
|
|
'status',
|
|
'last_login_at'
|
|
];
|
|
|
|
public function file()
|
|
{
|
|
return $this->belongsTo(File::class);
|
|
}
|
|
|
|
public function comments()
|
|
{
|
|
return $this->hasMany(Comment::class);
|
|
}
|
|
public function permissions()
|
|
{
|
|
return $this->hasMany(AdminPermission::class);
|
|
}
|
|
public function hasPermission(string $permission): bool
|
|
{
|
|
if ($this->role === AdminRole::SUPERADMIN) {
|
|
return true;
|
|
}
|
|
|
|
return $this->permissions()
|
|
->where('permission', $permission)
|
|
->exists();
|
|
}
|
|
}
|