JustinTime JustinTime - 2 months ago 12
PHP Question

Cant save a appointment in laravel

Right now I can delete my appointment but can't save it.

This is my delete function :

public function destroy($id)
{
$appointment = Appointment::find($id);
$appointment->delete();

return redirect( '/appointments' );
}


And this is my save function

public function update($id)
{
$save_appointment = Appointment::find($id);
$save_appointment->save();

return redirect('/appointments');
}


For some reason it's not updating. The
id
is 100% correct. What am I doing wrong. Is it because I have in my Appointment
model
this :

protected $fillable = [
'gender', 'options', 'user_id',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];

Answer

Your function should be like this:

public function update(Request $request, $id)
    {
    $save_appointment = Appointment::find($id);
    $save_appointment->update($request->all());
    $save_appointment->save();

    return redirect('/appointments');
}