Understanding the RESTful API Resources (Models) and its Relationships

JuanD MeGon
A free video tutorial from JuanD MeGon
Online instructor, web developer, master & systems engineer
4.5 instructor rating • 16 courses • 19,921 students

Lecture description

Let's go one by one with the different models/entities/resources that will conform the RESTful API, its attributes names, characteristics, and relationships between them.

Learn more from the full course

RESTful API with Laravel: Build a Real API with Laravel

Build a RESTful API for a market system using Laravel and dominate the most challenging features of APIs with Laravel

14:42:27 of on-demand video • Updated June 2020

  • Create your own projects with Laravel (not only RESTful APIs)
  • Make the most of your work tools (Sublime Text 3, Git, Github, Composer, PHP artisan and Laravel)
  • Generate and maintain the structure of the database in an automated way with Laravel and the PHP Artisan console
  • Use PHP Artisan effectively and be much more efficient
  • Create and configure your own local development environment
  • Properly configure your development environment for all your projects
  • Hone the main HTTP methods/verbs for HTTP and RESTful APIs
  • Use free professional tools to improve your productivity
English Before to start the implementation of whatever project or application that you want to create, you need to be sure that you understand the requirements and the design of that specific application. In the case of our RESTful API, I previously design a very useful entity relationship model that is going to allow us to understand every relation that exist and how every one of them interact with the other. We check this model here, we have several entities. We have a "User", "Buyer", "Seller", "Transaction", "Product" and "Category". As you can see "Buyer" and "Seller" inherits from user, it means that "Buyer" and "Seller" are both users of our system. It additionally means that in a specific moment, a specific user can be a "Buyer" and a "Seller". But we have a restriction, of course, a "Buyer" can't buy a product from himself and a "Seller" can't sell any product from himself. This is our first restriction. Then we can see that a "Buyer" has several transactions, it means a "Buyer" can purchase several products through a transaction. So as you can see a "Transaction" has a "Buyer", it means who purchase that product. And here we have the definition of that product. So at the end a transaction has a quantity the "Buyer" and the "Product". Then we have that a "Seller" has several products. So at the moment that a "User" publish a product, it automatically is understood by our project as a "Seller". So in fact a "User" or a "Seller" may have several products. And additionally a "Product" has several categories while a category may have several products. It means a relationship of many to many. We are going to see, of course, how to deal with this using a pivot table. Additionally, we're going to see how to manage and how to handle the inheritance between user "Buyer" and "Seller". So in the details here we can see that a "Product" has an id, a name, a description, a quantity, a status, a seller, transactions and categories. So the "Transaction" originally has a quantity, it means that every time that a product is sold the quantity available of this product is going to be reduced by the quantity of this. And additionally if the quantity of a transaction that is going to be created exceeds the quantity available the product, the transaction can not be created. And now for the "User". The "User" has a name, an email, a password, a verified field, a verified token and an admin. The verified field is to know if that user has an email verified and the verification token is used basically to verify that email. Using that verification token we are going to be sure that the user, click a link and verified his email. And finally we have an admin attribute that allows us to know if that user is an admin or not. So we have now an general understanding of the design of this RESTful API. See you in the next class.