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
Creating Models and Migrations
Factories and Seeders
Verify Database Records with Tinker
Seeding the Database Review
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
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
Testing Author Resources and Routes
Testing Book Resources and Routes
Data and Resource Review
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!