Laravel:如果匹配显示结果,则检查两列

时间:2015-03-11 11:16:02

标签: laravel

    $locationId=Auth::user()->location_id;
    $parcelDetails = $this->model
        ->whereBetween('date',array($fromDate, $toDate))
        ->where('source_from',$locationId)
        ->orWhere('destination_to',$locationId)
        ->with('sourceFrom', 'destinationTo')
        ->paginate($perPage);
        //get();
    return $parcelDetails;

我希望得到的结果是我的source_from或destination_to与$ locationId匹配给定的日期。

1 个答案:

答案 0 :(得分:0)

您可以使用nested where来完成该任务:

$locationId=Auth::user()->location_id;
$parcelDetails = $this->model
    ->whereBetween('date',array($fromDate, $toDate))
    ->where(function($q){
        $q->where('source_from', $locationId);
        $q->orWhere('destination_to', $locationId);
    })
    ->with('sourceFrom', 'destinationTo')
    ->paginate($perPage);
    //get();
return $parcelDetails;