B
B
babyflowercry2018-12-24 11:00:01
API
babyflowercry, 2018-12-24 11:00:01

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

2 answer(s)
D
Dmitry Kuznetsov, 2018-12-24
@dima9595

Solve this issue on the server side or do a get, post, update, delete for each table and shift the responsibility to the frontend?

This is just the server that processes it, so you won’t be able to shift anything to the front.
If I correctly understood the essence of the issue, then here you need to think more not about the API, but about the structure of the logic itself. Those. you must first decide what you want to achieve, and then think about how to compose the API correctly.
PS: I can be mistaken in understanding the issue, if I understood it wrong, then I apologize.

E
eugenezadorin, 2019-01-02
@eugenezadorin

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 question

Ask a Question

731 491 924 answers to any question