July 2018
Intermediate to advanced
420 pages
8h 46m
English
It is extremely simple to protect our routes using the application controllers. All we have to do is edit the Controller files and add the following code.
Open project/Http/Controllers/API/BikeController.php and add the following code right before the GET method:
/**
* Protect update and delete methods, only for authenticated users.
*
* @return Unauthorized
*/
public function __construct()
{
$this->middleware('auth:api')->except(['index']);
}
The previous code means that we are using the auth:api middleware to protect all bikers routes except for the index() method. So, our users can see the bike list, but, to see the bike's details and post a bike, they must be logged in. Later, in the Chapter09 , Creating Services ...
Read now
Unlock full access