How to redirect with slugs using Laravel

1.9k views Asked by At

I have the following controller:

public function postupdate($subject, $id)

//my code

return Redirect::route('webupdate'); // This code is wrong

The route below is where I want to redirect to but how do I redirect while including both slugs from the controller above?

Route:

Route::get('/updateweb/{subject}/{id}/', array( 'as' => 'webupdate', 'uses' => 'WebController@updatefunc'));
2

There are 2 answers

7
Jilson Thomas On
  return Redirect::route('webupdate', ['subject'=>$subject, 'id'=>$id]);

OR

  return Redirect::route('webupdate', [$subject, $id]);
7
ahmet2106 On

Simply

return Redirect::route('webupdate', array($subject, $id));

or

return Redirect::route('webupdate', array('subject' => $subject, 'id' => $id));

If you have only one slug, you could also do

return Redirect::route('routename', $id);

Read more about Redirects in Laravel 4.2 here