Creating and updating the controller function

  1. Open your Terminal window and type the following command:

php artisan make:controller API/BuilderController --api

Note that the --api flag creates four methods for us inside the BuilderController class:

  • index() = GET
  • store() = POST
  • show($id) = GET
  • update(Request $request, $id) = PUT
  • destroy($id) = POST
  1. Open project/app/Http/Controllers/API/BuilderController.php and add the App\Builder code right after the Controller import.

  2. Now, let's add the content for each method. Open project/app/Http/Controllers/API/BuilderController.php and replace the content with the following code:

<?phpnamespace App\Http\Controllers\API;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use App\Builder; ...

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.