Laravel Route Redirect and Route View

Created on November 9th, 2017

In Laravel 5.5, there are 2 new route methods which are Route::redirect() and Route::view.

If you want to easily redirect one route to another you can do so using the redirect() method:

Route::redirect('this-url', 'to-that-url');

Additionally, if you wish to map a route to a specific view you can do that in one line with the view() method:

Route::view('blog', 'blog.index');

Using these new methods will make your code cleaner and it will allow you to leverage Route Caching, whereas you would not be able to leverage Route Caching if you used closures to perform the functionality above.

Using closures would have looked like this:

Route::get('this-url', function(){
    return redirect('to-that-url');

Route::get('blog', function(){
    return view('blog.index');

So, you can see it looks much cleaner to use the new redirect and view methods.

Comments (0)