Stiliyan
Stiliyan

Reputation: 176

laravel update table returns error

I have the following issue when I try to update the laravel table I send my data via ajax everything is good. But the update returns an error.

the following function receives the data and updates the table.

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;
}

I also tried this query:

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

Any idea what am I doing wrong.

Upvotes: 1

Views: 49

Answers (1)

curious_coder
curious_coder

Reputation: 2468

Error is because update function accepts array. Correct syntax is

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

Also the correct syntax for fetching resquest inputs are

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

Upvotes: 4

Related Questions