Custom value in Relation
Closed this issue · 1 comments
Hi!
Is it possible to add a custom value within a record using Relation in the Builder in combination with $belongsToMany?
For example, I have a recipe site where I want to add the ingredients to a recipe. Now, the quantity of flavour is fixed based on an ingredient within Ingredients but the quantity could differ per recipe.
Similar to this: https://blog.quickadminpanel.com/laravel-belongstomany-add-extra-fields-to-pivot-table/
Take a look at the nameFrom
option in the relation form field. You can define a custom accessor here to display whatever you like. Here's how to define one in a model: https://docs.octobercms.com/2.x/database/mutators.html#defining-an-accessor
This also assumes that you have pivot data set up in your model definition: https://docs.octobercms.com/2.x/database/relations.html#retrieving-intermediate-table-columns
I hope this helps!