college-courses/app/Traits/HasRole.php

32 lines
392 B
PHP
Raw Permalink Normal View History

2024-10-15 10:15:40 +03:00
<?php
namespace App\Traits;
use App\Models\Role;
trait HasRole
{
private $roleClass = Role::class;
function role()
{
return $this->belongsTo($this->roleClass);
}
function getRole()
{
return $this->role()->first();
}
function roleName()
{
return $this->getRole()->name;
}
function isRole($name): bool
{
return $this->roleName() === $name;
}
}