0

我在名为“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);
}

请帮忙

4

1 回答 1

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 ]
    ];
}
于 2018-08-28T06:28:52.243 回答