gpt4 book ai didi

laravel - Yajra App\User 没有可用的引擎

转载 作者:行者123 更新时间:2023-12-05 05:16:57 26 4
gpt4 key购买 nike

我已经为我的 cms 管理员角色做了现在我有 2 个管理员角色 super 管理员和普通管理员我有一个管理用户的页面, super 管理员和普通管理员都可以看到它,但数据不同

这是 Controller 代码

  public function index()
{
$this->super_admin_role_check();
return view('admin.users.index');
}



public function usersList(){
$super_admin_role = Role::where('name','super_admin')->first();
$is_super_admin=$this->isSuperAdmin();

if($is_super_admin){
$data = User::all();
}else{
// Admin can get all users except super admin
$super_admin = DB::table('role_user')->where('role_id',$super_admin_role->id)->first();
$data = User::where('id','!=',$super_admin->user_id)->first();
}

if(!$data){
$data=[];
}
return DataTables::of($data)->make(true);
}




// This function check if the super_admin roles exist or not
public function super_admin_role_check(){

$user = Auth::guard()->user();

$super_admin_role = Role::where('name','super_admin')->first();

if(!$super_admin_role){

\Artisan::call('db:seed');

// if there's no role factory create super_admin role and assign it to the super admin user
$super_admin_role = Role::where('name','super_admin')->first();

DB::table('role_user')->insert([
'user_id'=>$user->id,'role_id'=>$super_admin_role->id
]);

$permissions = Permission::all();

// here i give all permissions to the super admin
foreach($permissions as $permission){

DB::table('permission_role')->insert(['permission_id'=>$permission->id,
'role_id'=>$super_admin_role->id
]);
}
}
return $super_admin_role;
}








// This Function Check if the user is super admin?
public function isSuperAdmin(){
$user = Auth::guard()->user();
$super_admin_role = Role::where('name','super_admin')->first();
$is_super_admin = DB::table('role_user')->where('user_id',$user->id)->where('role_id',$super_admin_role->id)->first();
return $is_super_admin;
}

问题是,当我以 super 管理员身份登录时,一切顺利,但当我以普通管理员身份登录时,出现错误“App\User 没有可用的引擎” 在\vendor\yajra\laravel-datatables-oracle\src\DataTables.php有什么帮助吗?

最佳答案

用这个?
$data = User::where('id','!=',$super_admin->user_id)->get();

关于laravel - Yajra App\User 没有可用的引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49840086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com