Laravel - What is the best solution: User define new fields in tables or create records as fields

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Laravel - What is the best solution: User define new fields in tables or create records as fields



I am working with laravel 5.5 to create a management system and this system has two types of user:



Designer: This user can create new customer details field like: cust_phone_number and select the type of this field like text or select or phone.



User: This user can only fill that field.



The design process is going excellently but the process of filling the fields has confounded me.



My question is:



What is the best solution to do achieve this goal? Is it better to enter form field data as fields in a database table or enter it as records?



edit:



I think my question was not exactly clear my problem not with relationship look friends I have two tables like this:
1- conf_fields table this table used designer to create customers form fields and this table contain many fields Only three fields interest us there is :
-conf_fields.field_name

This is name generated by the system and is a unique name
-conf_fields.field_label

This label is generated by the user and is a unique label
-conf_fields.field_render_type

This field allows the designer to select the field type like select or text or email or else

@ and the system by default insert three records as follows
- 1, customer_name_field ,Customer name , text
- 2, passport_number_field ,Passport number , text
- 3, email_field , Email , email



2-customers table this field contain the main fields that system created by default and this table used by normal user to fill the customers data and this table contain four columns as follows :
id,cust_name,cust_passport_number,cust_email



ok It looks fine but What if the manager asks the designer to add new fields, for example, phone number, address or other information? Well the designer can add it to the database and it will appear in the user's form, but when the fields are filled by the user where the values ​​of the new fields will go ? this is the question




3 Answers
3



I would use a Polymorphic relationship for that: https://laravel.com/docs/5.6/eloquent-relationships#polymorphic-relations


user
id - integer
email - string
password - string
profile_id - integer
profile_type - string

designer_profiles
id - integer
phonenumber - string
...

user_profiles
id - integer
first_name - string
last_name - string
....



Please take care of this issue, when you use that solution:
https://github.com/laravel/framework/issues/24787



As I understand your question, the Designer and User only differ in their permissions (adding new customer fields or only filling existing fields). If so, I would recommend using a solution for managing roles and permissions (for example https://github.com/spatie/laravel-permission).



very thanks I found the best solution for now and that is by insert the new fields as record like field_name,field_label,render_as,validate_as
But I am afraid of poor performance when data is inflated






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered