81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class Admin extends Authenticatable
|
|
{
|
|
use Notifiable, HasRoles;
|
|
use SoftDeletes;
|
|
|
|
/**
|
|
* Set the default guard for this model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $guard_name = 'admin';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'email', 'password',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
];
|
|
|
|
public static function getpermissionGroups()
|
|
{
|
|
$permission_groups = DB::table('permissions')
|
|
->select('group_name as name')
|
|
->groupBy('group_name')
|
|
->get();
|
|
return $permission_groups;
|
|
}
|
|
|
|
public static function getpermissionsByGroupName($group_name)
|
|
{
|
|
$permissions = DB::table('permissions')
|
|
->select('name', 'id')
|
|
->where('group_name', $group_name)
|
|
->get();
|
|
return $permissions;
|
|
}
|
|
|
|
public static function roleHasPermissions($role, $permissions)
|
|
{
|
|
$hasPermission = true;
|
|
foreach ($permissions as $permission) {
|
|
if (!$role->hasPermissionTo($permission->name)) {
|
|
$hasPermission = false;
|
|
return $hasPermission;
|
|
}
|
|
}
|
|
return $hasPermission;
|
|
}
|
|
}
|