Yajra App \ User没有可用的引擎

时间:2018-04-15 08:42:33

标签: laravel yajra-datatable

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

这里是控制器代码

  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;
    }

问题在于,当我以超级管理员身份登录时,一切顺利,但当我以正常管理员身份登录时,我会收到错误" App \ User"  在\ vendor \ yajra \ laravel-datatables-oracle \ src \ DataTables.php中 有什么帮助吗?

3 个答案:

答案 0 :(得分:1)

先删除()。由于您只返回一行。

$data = User::where('id','!=',$super_admin->user_id);

这应该有效

答案 1 :(得分:0)

这个? Google Cloud SDK 197.0.0 bq 2.0.31 core 2018.04.06 gsutil 4.30

答案 2 :(得分:0)

我注意到在使用 Yajra Laravel DataTables 库时会出现此错误,更具体地说,当您只检索单个模型并将其传递到 of(...) method 时。

以下是检索单个模型的一些示例,其中当检索到的模型直接传递到库的 No available engine for App\\Models\\ModelName at project-root-path\\vendor\\yajra\\laravel-datatables-oracle\\src\\DataTables.php:63 方法时,库将抛出错误 (DataTables::of(/* model here */)->make(true))。

Retrieving Single Models / Aggregates

// Retrieve a model by its primary key...
$flight = Flight::find(1);

// Retrieve the first model matching the query constraints...
$flight = Flight::where('active', 1)->first();

// Alternative to retrieving the first model matching the query constraints...
$flight = Flight::firstWhere('active', 1);

我通过将检索到的模型包装在数组中解决了这个问题。即:

$model = User::where('id','!=',$super_admin->user_id)->first();

DataTables::of($model ? [$model] : [])
            ->make(true);

旁注:如果找不到模型,Eloquent 的 first()find()firstWhere() 方法返回 null

测试"yajra/laravel-datatables-oracle": "~9.0" // Specifically v9.17.1