Yajra DataTable搜索栏不起作用

时间:2018-08-28 04:25:27

标签: laravel-5.4 yajra-datatable

我在名为“ directoryDataTable.php”的文件中使用了“左联接查询”。现在的问题是Yajra DataTable搜索栏不起作用。它既没有给出任何错误,也没有给出搜索结果。

我的DataTable查询功能如下。

 public function query()
{
    $id = \Illuminate\Support\Facades\Auth::user()->id;
    $directories = DB::table('directories')
        ->leftjoin('claimed', 'directories.id', '=','claimed.dir_id')
        ->select('directories.*')
        ->where('directories.user_id',$id)
        ->where('paymentStatus','1')
        ->whereNull('directories.deleted_at')
        ->orWhere('claimed.claimed_by',$id);


   return $this->applyScopes($directories);
}

请帮助

1 个答案:

答案 0 :(得分:0)

将查询更改为

public function query()
{
    $id = \Illuminate\Support\Facades\Auth::user()->id;
    $directories = DB::table('directories')
        ->leftjoin('claimed', 'directories.id', '=','claimed.dir_id')
        ->select('directories.*')
        ->where(function ($query) {
            $query->where('directories.user_id',\Illuminate\Support\Facades\Auth::user()->id)
                ->orWhere('claimed.claimed_by',\Illuminate\Support\Facades\Auth::user()->id);
        })
        ->where('paymentStatus','1')
        ->whereNull('directories.deleted_at')
        ;

    return $this->applyScopes($directories);

}

并在“获取列”功能中,像这样替换[[name] =>'YourTableName.ColumnName','data'=>'YourColumnName']。

private function getColumns()
{
    return [
        'dir_name' => ['name' => 'directories.dir_name', 'data' => 'dir_name'],

        'phone_number' => ['name' => 'directories.phone_number', 'data' => 'phone_number'],

        'address' => ['name' => 'directories.address', 'data' => 'address'],

        'features' => ['name' => 'directories.features', 'data' => 'features', ],

        'Status' => ['name' => 'directories.Status', 'data' => 'Status','searchable'=>false ],

        'Subscription' => ['name' => 'directories.Subscription', 'data' => 'Subscription','searchable'=>false ]
    ];
}