Using Middleware in laravel5route does not work

Source: Internet
Author: User
Routes. add the Route: get (& #039; apiindex & #039;, & #039; ApiController @ index & #039;, [& #039; middleware & #039; to the PHP file; & amp; gt; & #039; auth & #039;]); however, this middleware is useless. google writes this in route, but why am I not here? Add the routes. php file
Route: get ('/api/Index', 'apicontroller @ Index', ['middleware' => 'auth']);
But I found that this middleware didn't work. google wrote this in route, but why am I not here?

Reply content:

Add the routes. php file
Route: get ('/api/Index', 'apicontroller @ Index', ['middleware' => 'auth']);
But I found that this middleware didn't work. google wrote this in route, but why am I not here?

What is the specific function?

Check whether the $ routeMiddleware array in Kernel. php contains

'auth' => 'App\Http\Middleware\Authenticate',

The nathan_wu reply is correct, because I have a problem with the writing method. The correct writing method should be as follows:
Route: get ('home ',[
'Middleware '=> ['auth'], // use the roles middleware
'Uses '=> 'homecontroller @ Index ',
]);
But I first wrote an article from google to a foreigner, which was written in soy sauce,
$ Router-> get ("/awesome/sauce", "AwesomeController @ sauce", ['middleware '=> 'auth']);
So he just imitated his writing. The result middleware didn't work. It may be a laravel version.

Solve the problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.