edms2023/app/Permission.php

34 lines
822 B
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'permissions';
protected $fillable = [
'name',
'display_name',
'description',
];
public static function getPermittedUsersList($pid)
{
$deps = PermissionRole::where('permission_ids', 'LIKE', '%"'.$pid.'"%')->pluck('department_id')->toArray();
$roles = PermissionRole::where('permission_ids', 'LIKE', '%"'.$pid.'"%')->pluck('role_id')->toArray();
$u = User::whereIn('department_id', $deps)->whereHas('role_user', function($q) use($roles){
$q->whereIn('role_id', $roles);
})->get(['id', 'first_name', 'last_name']);
return $u;
}
}