【发布时间】:2017-06-04 03:02:08
【问题描述】:
我想在 Laravel 中编写一个动态更新查询,它接受参数并且可以在整个项目中使用。
以下是我的控制器功能:
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('Admin_controller@cities_page')->with('status','Record Updated Successfully!');;
}
下面是我的模型函数:
public static function editrecord($data,$wher,$tbl)
{
return DB::table($tbl)->where($wher)->update($data);
}
这里唯一的问题是我无法将值 ('city_id',1) 存储在 $wher 变量中。这是错误的屏幕截图: link to the image file
有没有其他方法可以做到这一点。请帮忙。
【问题讨论】:
标签: php laravel laravel-5 where-in