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