How to save and load data from select type elements that do not have the saved description in the database

jackrsantana posted 1 year ago

Good night people! Could anyone please tell me, what would be the best practice for saving and loading data from select type elements that do not have the description saved in the database?

I am currently saving only the id of the selected option and at the time of displaying, I created a translation file that generates the description from the id. But I guess that's not the best way. I did this because I did not know better. And besides, since I use AngularJS to display the values on the screen, I can not integrate it with the blade.

These are fixed fields, where the user can not enter new values. Example: Type of person (Physical or Legal), Type of contact (email, telephone or fax). In these cases, I save only a number that represents that description, rather than saving the entire description.

Would anyone have a better suggestion? Thank you in advance.

ndy40 replied 1 year ago

Why not save the entire thing in the database and when you returning data to AngularJS, you return everything as part of ur response.


Type of Person table
id -> Int
name -> Person 

User Table 
id -> PK
username -> String
type_of _person_id -> INT  Foreign Key  back to Type of Person table.

Using the Eloquent ORM, you can load all the data you need with their accompanying description from the database and parse them in AngularJS.

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us