使用雄辩地搜索具有多个值的多个列

问题描述 投票:0回答:1

我需要雄辩地搜索3张桌子

让我说这些值

$periodStart = $request->input('periodStart');
        $periodEnd = $request->input('periodEnd');
        $from_destination_name = $request->input('from_destination_name');//this must be from_destination_id
        $to_destination_name = $request->input('to_destination_name');//this must be to_destination_id
        $type = $request->input('type');

periodStart,periodEnd和类型来自相同的表,名为transfers,

from_destination_id和to_destination_id已经来自转帐表,但我需要通过其ID获取每列的目标名称,

我尝试过:我从中得到了一些数据,但不是真正的方法

$bookingTransfersData = DB::table('transfers as t')
            ->join('destinations as d', function ($join){
                $join->on(DB::raw('find_in_set(t.from_destination_id,d.destination_id)'),
                    DB::raw('find_in_set(t.to_destination_id,d.destination_id)'));
            })->join('vehicles as v','t.vehicle_id','=','v.vehicle_id')
            ->select('t.periodStart as periodStart', 't.periodEnd as periodEnd','d.destination_id as destinationId','d.name as destinationName', 't.type')->get();

但是这里没有与上述数据匹配的数据。 :(

$searchResults = $bookingTransfersData
            ->where($periodStart,'like','%'.'periodStart'.'%')
            ->where($periodEnd,'like','%'.'periodEnd'.'%')
            ->where($from_destination_name,'like','%'.'destinationName'.'%')
            ->where($to_destination_name,'like','%'.'destinationName'.'%')
            ->where($type,'like','%'.'Type'.'%');

请帮助:)

laravel search eloquent searchable sql-search
1个回答
0
投票

首先,在where之后不能使用get()方法,因此从->get()查询中删除$bookingTransfersData

其次,您的where方法存在语法错误,

where(string | array |关闭$ column,混合$ operator = null,混合$ value = null,字符串$ boolean ='and')

所以您需要像这样更改代码:

$searchResults = $bookingTransfersData
            ->where('periodStart','like','%'.$periodStart.'%')
            ->where('periodEnd','like','%'.$periodEnd.'%')
            ->where('destinationName','like','%'.$from_destination_name.'%')
            ->where('destinationName','like','%'.$to_destination_name.'%')
            ->where('Type','like','%'.$type.'%');
© www.soinside.com 2019 - 2024. All rights reserved.