Redirect after update Readable

Asked

Viewed 576 times

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:

inserir a descrição da imagem aqui

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?

1 answer

2


Informs the url for redirect:

return redirect('/agenda_exames)->with('success','Os dados foram atualizados com sucesso.');
  • Thanks for the feedback! I edited the question, I already own this route.

  • I changed my answer. Which version of Laravel tas using?

  • I am using Laravel 5.5. I tested with your example but still giving route error.

  • I edited the answer. Take a look to see if you will redirect informing the url directly on redirect.

  • It worked out! Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.