I'm trying to figure out how to implement an edit function. I know that its similar to the create function but instead of creating a new object you find the existing object through its id, however I cant seem to figure out how to do it.
public function edit()
{
//
return view('modules.update');
}
public function update(Request $request, $id)
{
//
$module = Module::find($id);
$module->course = $request->course;
$module->save();
return redirect('/modules/all')->with('created', 'post Created');
}
You are trying to save to the edit route (PUT). The edit route is normally a get route where you have a form you can update
public function edit(Post $post)
{
return view('modules.edit', $post);
}
//assuming this is the edit view
<form method="post" action="/modules/update/{{$post->id}}" enctype="multipart/form-data"> //or whatever your update url is
I've got the form to work, however instead of updating it fully replaces every value. Is there any way to fix this without having to use {{old($data->name)}}