From the course: Building RESTful APIs in Laravel

Unlock the full course today

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

Solution: Building the author resource

Solution: Building the author resource

From the course: Building RESTful APIs in Laravel

Start my 1-month free trial

Solution: Building the author resource

(upbeat music) - [Teacher] Let's see how we can create author resource. First of all, let's add a name column to the author's table. Now we need to migrate the database. Let's run php artisan migrate in our terminal. Next, let's add a name field to the fillable array on the author model, otherwise seeding our database will fail. Now let's open the author factory class, and return name as an instance of the faker name property. Let's go to the AuthorSeeder class and create 10 authors. Let's import the author model at the top of the file. Finally, let's seed the author's table with some fake data. Now that we have our data ready, let's return an author collection on the index method of the AuthorController. Make sure you import AuthorCollection at the top of the file. Let's return a single author resource on the show methods, and again, import AuthorResource at the top of the file. You could have also wrote the AuthorCollection…

Contents