Redirect after update laravel

0

I'm working on a project with laravel and I came across a problem. After the 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 this error returns me:

If I use this redirect, there is no error:

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');

Get the data for editing

Route::get('/edita_exames/{id}', 'AgendaExamesController@edit')->name('edita_exames');

Update your 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 methods presented?

    
asked by anonymous 27.01.2018 / 23:51

1 answer

1

Informs url by redirect :

return redirect('/agenda_exames)->with('success','Os dados foram atualizados com sucesso.');
    
28.01.2018 / 01:21