bff0c7ea4d
git commit "Implement admin roles and permissions system"
49 lines
876 B
PHP
49 lines
876 B
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class AdminRole
|
|
*
|
|
* @property int $admin_id
|
|
* @property int $role_id
|
|
*
|
|
* @property Admin $admin
|
|
* @property Role $role
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class AdminRole extends Model
|
|
{
|
|
protected $table = 'admin_roles';
|
|
public $incrementing = false;
|
|
public $timestamps = false;
|
|
public static $snakeAttributes = false;
|
|
|
|
protected $casts = [
|
|
'admin_id' => 'int',
|
|
'role_id' => 'int'
|
|
];
|
|
|
|
public function roles()
|
|
{
|
|
return $this->belongsToMany(Role::class, 'admin_roles');
|
|
}
|
|
|
|
|
|
public function hasPermission($permission)
|
|
{
|
|
return $this->roles()
|
|
->whereHas('permissions', function ($query) use ($permission) {
|
|
$query->where('slug', $permission);
|
|
})
|
|
->exists();
|
|
}
|
|
}
|