Sunday, 5 November 2017

Laravel new Features in Routing methods in laravel

Laravel 5.5 shipped a couple of convenient shortcuts to the Laravel Router class that eliminates the need for creating a controller or closure only to return a simple view or redirect.

1. Route::view
2. Route::redirect

Here we will see clear information regarding route functions.


The Route::view method

The Route::view method eliminates the need for routes that only need a view returned. Instead of using a controller or a closure, you can define a URI and a path to a view file:


// resources/views/pages/about.blade.php
Route::view('/about', 'pages.about');
You can also pass in an array of variables that will be passed to the view:
Route::view('/about', 'pages.about', ['year' => date('Y')]);
The Route::redirect Method


The Route::redirect method also eliminates the need to create a controller or a closure only to return a redirect response:
Route::redirect('/homepage', '/home');
The third default argument, if not passed, is a 301 redirect. However, you can pass the third argument for a different status code. For example, if you want to create a 307 Temporary Redirect, it would look like this:
Route::redirect('/homepage', '/home', 307);

No comments:

Post a Comment

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in Laravel

  WampServer: Download this file:  http://curl.haxx.se/ca/cacert.pem Place this file in the  C:\wamp64\bin\php\php7.1.9  folder Open  php.in...

Popular Articles