我想在Laravel中編寫一個動態更新查詢,它接受參數並可用於整個項目。Laravel 5.4:在變量中存儲'Where'子句
以下是我的控制器功能:
public function editquery(Request $request)
{
$city_id = $request->input('city_id');
$city_name = $request->input('city_name');
$tbl = 'city';
$data = ['city_name'=>$city_name];
$wher = ('city_id',1);
General_model::editrecord($data,$wher,$tbl);
return redirect()->action('[email protected]_page')->with('status','Record Updated Successfully!');;
}
下面是我的模型功能:
public static function editrecord($data,$wher,$tbl)
{
return DB::table($tbl)->where($wher)->update($data);
}
這裏唯一的問題是,我不能存儲的值( 'city_id',1)在$變量。這是錯誤的屏幕截圖: link to the image file
是否有任何其他方式來執行此操作。請幫忙。
謝謝。有用。你能否告訴我更多關於條件的信息。如何在$ conditions數組中使用AND&OR子句? –
@SameerAli更新了答案。 – Sandeesh
感謝您的回答。 :) –