Good practices on a GET request (Laravel API)

Asked

Viewed 70 times

0

Hello, I have a table with user login data and this table has relation with several other tables (FK). I’m doing an API using Laravel, but a question has arisen. If I do a GET in the Login table, using the user ID, which is best as good practice: 1. Make a relationship and when I give a GET in the Login table, using the user ID, already see the data of all related tables. OR 2. A "GET", for each table that has the FK with the ID of the Login table, so I would pass an ID in the request and each table would make the "query" individually. What I would like to do is to have an area with the data of this table of the user, so that he could change, delete, read..., but as they are distributed in other tables, I do not know what is best practice or that is not so heavy.

  • Depends on your need. If you just want to get essential user data after login it would be a good practice to search at once in the database, thus avoiding unnecessary requests. Since you already have relationships, you wouldn’t have pq search table by table at the time of login. In changing the data, you can send a json with the data to be modified and in the controller validate this data for which tables they are part.

  • Thanks for the help, in which case I will need essential user data after login, so I will search only then, as you suggested. Hug and thank you!

  • I’ll put the comment as an answer then, in case you’ve helped. Please mark it as chosen.

1 answer

0


Depends on your need. If you just want to get essential user data after login it would be a good practice to search at once in the database, thus avoiding unnecessary requests. Since you already have relationships, you wouldn’t have pq search table by table at the time of login. In changing the data, you can send a json with the data to be modified and in the controller validate this data for which tables they are part.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.