当我尝试更新laravel表时,我有以下问题我通过ajax发送数据一切都很好。但更新返回错误。
以下函数接收数据并更新表。
public function saveCalendar(Request $request) {
$calendar = $request->calendar;
$apartment_id = $request->apartment_id;
apartments::where('Apartment_ID', $apartment_id)->update(array('calendar' => $calendar));
$confirmation = 'Календара е запазен успешно !';
return $confirmation;
}
我也试过这个问题:
apartments::where('Apartment_ID', $apartment_id)->update('calendar' => $calendar);
知道我做错了什么。
答案 0 :(得分:4)
错误是因为update函数接受数组。正确的语法是
apartments::where('Apartment_ID', $apartment_id)->update(['calendar' => $calendar]);
获取resquest输入的正确语法是
$calendar = $request->input('calendar');
$apartment_id = $request->input('apartment_id');