Route::view() and Route::redirect() method with an example (Laravel 5.5)

Route::view() and Route::redirect() methods are eliminate the need for creating a controller or closure only to return a simple view or redirect.

Route::view() Method :

In this Method Instead of using a controller or a closure.

you can define a URI and a path to a view file(resources/views/pages/filename.blade.php).

Example :

// View File Path - resources/views/company/services.blade.php
Route::view('/services', 'company.services');

Route::view method accepts a URI as a first argument, View Name as a Second argument and in third argument you will pass array of variables.

You can also pass in an array of variables that will be passed to the view:

Route::view('/services', 'company.services', ['curdate' => date('d M Y')]);

Route::redirect() Method :

In this Method eliminates the need to create a controller or a closure only to return a redirect response.

Example :

Route::redirect('/offered-services', '/services');

 

 

You May Also Like

Leave a Reply

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