Please, anyone, explain what is reverse routing with example. I'm searching this question but still confused about this reverse routing concept.
For example the following route declaration tells Laravel to execute the action “signUp” in the controller “UsersController” when the request’s URI is ‘signUp’.
http://mycoolsite.com/signUp
Route::any('signUp’, 'UsersController@register’);
Traditionally, we may link to the registration page like this:
{{ HTML::link('signUp’, 'Register Now!’) }}
However, this has the unfortunate disadvantage of being dependent on our route declaration. If we change the route declaration to:
http://mycoolsite.com/signup
Route::any('register’, 'UsersController@signUp’);
Then our link will be wrong. We’ll have to go throughout our entire site and fix our links. Hope we don’t miss one!
Instead, let’s use reverse-routing.
{{ HTML::link_to_action('UsersController@signUp’, 'Register Now!’) }}
Now, the link that we generate will automatically change when we change our routing table. In our first example it’d generate http://mycoolsite.com/register
. Then, when we change the routes call to match our second example it’ll generate http://mycoolsite.com/signup
.
In traditional routing you depend on route declaration. In reverse routing on the some action(method, function)