User Profile custom fields DB decyphering

Solved
mikemastercorp

Aug 16th, 2022 11:08 AM

Hello boys and girls.

Have a small question about the storage of custom User Profile fields. So I created a new field called test inside the profile.blade.php, allowed it and I am able to populate and keep the data safely.

For my data cross reference needs of the project, I started wondering where this data is kept as obviously it goes to the DB and not in a file and since I was not sure where to search for, I just simply exported the DB SQL, opened it and found my string to be located at: "wave_key_values"

So looking at the rows, I found my custom fields there and it is now clear how can I access this data from the DB directly if a need be.

I am inquiring to know what are the intentions of the rows, as there are:

ID - clear (it is the ID of the custom data record) type - clear (that is the type of the field to use, e.g. text/text_area etc.) keyvalue_id - UNCLEAR keyvalue_type - UNCLEAR (the default value is users) key - clear (that is the given field name) value - clear (that is the populated value of the custom field)

So what is the purpose of "keyvalue_id" and "keyvalue_type" and in terms of the type, what other types I can have as a use case?

bobbyiliev

Aug 19th, 2022 09:54 AM

Best Answer

Hi there,

This is actually a good question. I believe that this was initially setup that way so that the wave_key_values table could be used for a general key value store, and not only for the user profile settings.

For more details, you can take a look at the wave/src/KeyValue.php file where the polymorphic relationship is defined.

That way, you can use this specific key value store model with different models, rather than only the Users model for example.

For more info on how Laravle impelemtns polymorphic relationships I could suggest the official docs here:

Laravel polymorphic relationship

Hope that this helps! Let me know if you have any questions.

Best,

Bobby

Report
1
mikemastercorp

Aug 21st, 2022 08:04 AM

Thanks Bobby. As usual a great answer pointing me to read a bit more but lay down with all the knowledge needed after the good read :)

Report
1
bobbyiliev

Aug 22nd, 2022 12:10 AM

No worries at all! Happy to help!