laravel update table返回错误

时间:2017-03-25 20:34:40

标签: laravel

当我尝试更新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);

知道我做错了什么。

1 个答案:

答案 0 :(得分:4)

错误是因为update函数接受数组。正确的语法是

apartments::where('Apartment_ID', $apartment_id)->update(['calendar' => $calendar]);

获取resquest输入的正确语法是

$calendar = $request->input('calendar'); 
$apartment_id = $request->input('apartment_id');