1
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class User extends Model
|
||||
{
|
||||
protected $table = 'users';
|
||||
protected $hidden = ['password'];
|
||||
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id');
|
||||
}
|
||||
|
||||
public function hasRole($role)
|
||||
{
|
||||
return $this->roles()->where('name', $role)->exists();
|
||||
}
|
||||
|
||||
public function hasPermission($permission)
|
||||
{
|
||||
return $this->roles()
|
||||
->whereHas('permissions', function($query) use ($permission) {
|
||||
$query->where('slug', $permission);
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user