HasOne关系全局搜索失败数据表

时间:2018-11-29 11:23:08

标签: laravel laravel-5 datatables eloquent yajra-datatable

问题摘要

我的用户模型与配置文件表有一个关系。现在当我尝试搜索任何东西时,搜索将永远无法正常工作,但是如果我删除关系列(profile.gender'),则搜索工作。

问题的代码段

        $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: '{{route('route)}}',
            'aaSorting' : [[0,'asc']],
            columns: [
                {data: 'id',name: 'users.id'},
                {data: 'name',name: 'users.name'},
                {data: 'mobile_number',name: 'users.mobile_number'},
                {data: 'profile.gender',name: 'profile.gender'},
                {data: 'is_active',name: 'users.is_active',searchable: false},
                {data: 'is_allowed',name: 'users.is_allowed',searchable: false},
                {data: 'action',searchable: false}
            ]
        });


    $users = User::with('profile');
      return DataTables::eloquent($users)
          ->addColumn('action', function ($user) {
              return '<a href="#edit-'.$user->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
          })
          ->editColumn('is_active', function($status){
              switch($status->is_active)
              {
                //0= Inactive, 1 = Active
                  case '0': return '<span class="label label-danger">Inactive</span>'; break;
                  case '1': return '<span class="label label-success">Active'; break;
                  default: return '<span class="label label-warning">Undefine</span>';
              }
          })
          ->editColumn('is_allowed', function($status){
              switch($status->is_allowed)
              {
                  //0= Inactive, 1 = Active
                  case '0': return '<span class="label label-danger">Not Allowed</span>'; break;
                  case '1': return '<span class="label label-success">Allowed</span>'; break;
                  default: return '<span class="label label-warning">Undefine</span>';
              }
          })
          ->rawColumns(['is_active', 'action','is_allowed'])
          ->blacklist(['created_at', 'updated_at','deleted_at','action','is_allowed','is_active'])
          ->toJson();

系统详细信息

  • yajra / laravel-datatables
  • PHP 7.3版
  • Laravel 5.7版
  • Laravel-Datatables版本8.x

0 个答案:

没有答案