Adding resources to controllers

Now, we need to make some minor changes to our controllers in order to use the resource we just created. To avoid any mistakes, we will look at the code for all of our controllers:

  1. Edit the Bike controller by replacing the content in App/Http/Controllers/API/BikeController.php with the following code:
<?phpnamespace App\Http\Controllers\API;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use App\Bike;use Validator;use App\Http\Resources\BikesResource;class BikeController extends Controller{    /**    * Protect update and delete methods, only for authenticated     users.    *    * @return Unauthorized    */    public function __construct()    {        $this->middleware('auth:api')->except(['index']);    }    /** * Display a listing ...

Get Hands-On Full Stack Web Development with Angular 6 and Laravel 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.