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 post we will give you information about Laravel 5.5 new feature – Route::view() and Route::redirect() method with example. Hear we will give you detail about Laravel 5.5 new feature – Route::view() and Route::redirect() method with exampleAnd how to use it also give you demo for it if it is necessary.

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.     returnview('dashboard');
  3. });
Route::get('/',function(){
	return view('dashboard');
});


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.     returnredirect('/dashboard');
  3. });
Route::get('/',function(){
	return redirect('/dashboard');
});

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

By using above shortcut, you do not write full routes or controller for loading simple view or simple redirection.

Label :

PHP

Laravel PHP Framework

How To

MVC

Web Development

Hope this code and post will helped you for implement Laravel 5.5 new feature – Route::view() and Route::redirect() method with example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  88  =  96

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US