Answer the question
In order to leave comments, you need to log in
How to make an API on Laravel?
Hello
I am writing an API in Laravel. There is a model Restaurant, consisting of 4 models, respectively, of 4 tables in the database. How to properly organize the API to work with such composite models, if, for example, it is planned to change the characteristics of the restaurant in the settings in the front-end, etc.? Solve this issue on the server side or do a get, post, update, delete for each table and shift the responsibility to the frontend?
Answer the question
In order to leave comments, you need to log in
Solve this issue on the server side or do a get, post, update, delete for each table and shift the responsibility to the frontend?
Try to make the API so that it is as convenient as possible to use. Put yourself in the place of a frontend developer and start from his possible tasks. The frontender should work with entities, it does not need to know exactly how they are stored on your server.
It's entirely possible that you'll need to implement methods to save a whole large batch of restaurant data. On the server side, you will independently distribute this data among the necessary tables.
But in addition, you can implement auxiliary API methods for selective saving to one of the four tables. For example, changing restaurant settings.
For example, there must be exactly one deletion method - knowing the ID of the restaurant, the user will be able to delete data from all tables in one call.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question