From the course: Building RESTful APIs in Laravel

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Creating an author resource infrastructure

Solution: Creating an author resource infrastructure

From the course: Building RESTful APIs in Laravel

Start my 1-month free trial

Solution: Creating an author resource infrastructure

(upbeat music) - [Instructor] Hopefully you were able to solve the challenge, but if not, don't worry, let's do it together now. We can create the Author model, migration factory, and seeder by using a single php artisan command. In our terminal, let's type php artisan make:model: Author, -m for migration, f for factory, s for seeder. Next, let's create an API controller and set Laravel route model binding on it. In the terminal, let's type php artisan make:controller AuthorController, and because we want this to be an API controller, we add the --api flag, and to set Laravel's route model binding on it, we do --model=Author. Enter. Fantastic. Now, let's create API resource for Author too. And while we add it, let's create the resource collection. In the terminal, we will type php artisan make:resource AuthorResource. And php artisan make:resource AuthorCollection. Fantastic. Now let's open our api.php file…

Contents