1
I’m working on a project with Laravel and I came across a problem. After Update I want to redirect the user to another specific page. In the update function of my Controller I have this code:
public function update(Request $request, $id){
try {
$exame = $request->all();
$id_exame = Tab_exames::findOrFail($id);
$id_exame->update($exame);
return redirect()->route('agenda_exames')->with('success','Os dados foram atualizados com sucesso.');
} catch (Exception $ex) {
return redirect('agenda_exames')->with('error', 'Ocorreu um erro ao tentar atualizar os dados!');
}
}
Only that returns me this mistake:
If I use this redirect no error occurs:
return back()->with(['success' => 'Os dados foram atualizados com sucesso.']);
My routes are like this:
Redirect
Route::get('/agenda_exames', 'AgendaExamesController@index')->name('agenda_exames');
Take data for editing
Route::get('/edita_exames/{id}', 'AgendaExamesController@edit')->name('edita_exames');
Updates the data
Route::put('/edita_exame/{id}', 'AgendaExamesController@update')->name('edita_exame');
How can I redirect the user to another page after the update using the presented methods?
Thanks for the feedback! I edited the question, I already own this route.
– Henqsan
I changed my answer. Which version of Laravel tas using?
– Diego Vieira
I am using Laravel 5.5. I tested with your example but still giving route error.
– Henqsan
I edited the answer. Take a look to see if you will redirect informing the url directly on redirect.
– Diego Vieira
It worked out! Thank you very much.
– Henqsan