Laravel过滤器使用条件

时间:2018-03-14 07:18:36

标签: laravel eloquent laravel-5.4 laravel-filters

我有一个名为product的雄辩模型。我需要使用where条件取决于同一个表中列的状态。这是我的代码

public function product_list(Request $request,Datatables $datatables){

    $product = Product::where('supplier_id',$request->supplier_id)->where('product','!=',3);

    return $datatables->eloquent($product)->filter(function ($query) use ($request) {
                    if($query->is_from_portalsite==1){
                        $query->where('status','>',1);
                     }
    })->make(true);

}

如果列is_from_portalsite等于1,我需要检查where条件。如何在laravel中检查。

1 个答案:

答案 0 :(得分:0)

试试这个(假设is_from_portalsite是布尔值):

$query->where('is_from_portalsite',0)->orWhere('status','>',1);