Hey fellow Laravel devs. I am building custom fields feature for my app and it has relationship to different models via polymorphic relations. when creating a new custom field, I provide model that this field belongs to so that I can attach it. The question is how should I implement updating and deleting these fields? Once created I can use the id of the custom field to update and delete it so is it okay to just pass the field id instead of passing model and field in the route?
Back
•
In response to @ilyosjon
By that moment, you should have something like this:
fields: id, fieldable_type, field_type, field_label, ...
custom_options: id, field_id, fieldable_id, fieldable_type.
And in your custom_options, the value will be something like:
1, 1, 1, App\Models\User
So if you have all required foreign key contraints with cascade delete, then removing the entry from `fields` table, the related `custom_options` will also be removed.
Hope I've answered your question or maybe I misunderstood it. In any case - feel free to ask, since I have made a similar solution 3 times already :D