Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.


Build a REST API with Laravel Course

via Treehouse


Build a REST API using one of the most popular PHP frameworks, Laravel. In this course you'll learn how to implement CRUD operations in a Laravel REST API using the MVC design pattern.

What you'll learn

  • Design a REST API
  • Build CRUD operations
  • Produce Resource Controllers
  • Implement Namespacing, Groups, and Route Name Prefixes
  • Produce Endpoints and Routes
  • Test API Endpoints


Seeding the Database

In this course, we’ll build a REST API with Laravel that allows you to submit your favorite books and authors. The REST API we’re building, from scratch -- can return a list of books with authors and also allows you to submit, update and delete books and authors. First, we need to spin up a Laravel project, then create and seed our database. Let’s get started!

Chevron 6 steps
  • Getting started


  • Migrations


  • Creating Models and Migrations


  • Factories and Seeders


  • Verify Database Records with Tinker


  • Seeding the Database Review

    10 questions

API Basics & CRUD operations

Now that we’ve set up our Laravel application and created factories that generate our test data, we’re ready to explore the differences between Controllers and Resource Controllers. The main difference between the two controllers is that Resource Controllers include all of the CRUD goodies, pre-built for us making this development task a snap. Let's get started!

Chevron 3 steps
  • REST, CRUD and Controllers


  • Resource Controllers (CRUD)


  • CRUD and More

    5 questions

Accessing Data with Resources

Why exactly do we want to use Resources? To answer this question, we’ll examine each piece of data and decide which specific pieces will be displayed to the API consumer. For example, it's best practice to hide author IDs, timestamps and passwords because we don’t want to share sensitive or irrelevant data to the users of our API. It’s also worth noting that exposing Author ID’s can give your API consumers an idea of the size of your database which you may not want to make public.

Chevron 5 steps
  • Routes


  • Resources


  • Testing Author Resources and Routes


  • Testing Book Resources and Routes


  • Data and Resource Review

    4 questions

Clean Routes and Validation Messages

You created a Laravel app, connected the MySQL database, migrated then seeded the database using Factories. On top of that, you built CRUD operations using controllers, removed database-specific data using Resources, and combined it all with building your very own REST API using the Laravel framework. In this section, we're going to add the finishing touches to optimize our Routes and make them scalable and clean. Clean routes will allow you to work with large applications that use a large number of Routes. Let's get started!

Chevron 4 steps
  • Clean Routes


  • Custom Error Messages


  • Closing thoughts


  • Routes and Validation Review

    5 questions

Taught by

Abrahm Overcast

Related Courses


Start your review of Build a REST API with Laravel Course

Never Stop Learning!

Get personalized course recommendations, track subjects and courses with reminders, and more.

Sign up for free