Laravel 5.5 new feature - Route::view() and Route::redirect() method with example

Laravel 5.5 new feature - Route::view() and Route::redirect() method with example

In this tutorial, I will tell you the new features Route::view() and Route::redirect() helpers added with Laravel 5.5.

Route::view()

Sometime you need to return only a view then you define a route and then return view using view() helpers function.

With the release of Laravel 5.5, You can use the Route::view method that provides a easier shortcut load view for a URI.

Route::view method accepts a URI as a first argument and in second argument you will pass the view name.

Before Laravel 5.5

Before Laravel 5.5, If you need to return view only for specific URI then you were using the following syntax :

  1. Route::get('/',function(){
  2.     return view('dashboard');
  3. });
With Laravel 5.5

Laravel 5.5 provides the shortcut for achieving the above functionality in single line:

Route::view('/','dashboard');
Route::redirect()

Route::redirect method provides the shortcut to redirect from one URI to another URI.

Before Laravel 5.5

Sometime you want to redirect to a specific URI by accessing another URI then you defined the route with particular URI and then redirect to specific URI using the redirect method in following way :

  1. Route::get('/',function(){
  2.     return redirect('/dashboard');
  3. });

In the above example, If a user hits the root url then he will be redirected to the dashboard.

With Laravel 5.5

You can achieve the same functionality by using Route::redirect() method in following way :

Route::redirect('/','dashboard');

Phone: (+91) 8800417876
Noida, 201301
Attention Required! | Cloudflare

Sorry, you have been blocked

You are unable to access ressim.net

Why have I been blocked?

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.