我的用户模型与配置文件表有一个关系。现在当我尝试搜索任何东西时,搜索将永远无法正常工作,但是如果我删除关系列(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();