You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two models Locations and Vaccines that are related via a belongsToMany relationship using a pivot table inbetween. There is a model for the pivot called LocationVaccine and aside from the location_id and vaccine_id there is a piece of intermediate data "is_required" that is a boolean to state whether that vaccine is required (true), or just recommended (false) in that location.
Currently I am able to load and save Vaccines to a new or existing location no problem, however I am struggling to find a solution that will allow me to choose whether or not a selected vaccine is required or not. I am using a select at the moment with the ->pivotData() function where I can set "is_required" to true or false, but that is only at the top level of the select, not for each selected option.
The only solution I can think of right now is to introduce a second pivot and relationship between vaccines and have two different selects in my filament form, one that inserts into the existing pivot table for required vaccines and the new one that inserts into the new pivot and loads via the new relationship. I am sure this will work but it feels very "un-laravely" to have two pivots and relationships to track something that should be tracked with intermediate data on the single pivot table.
Has anyone any suggestions as to how I can achieve this? Maybe I'm using the wrong type of filament field that would make this much simpler?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Package
Panel builder
Package Version
v3.2.0
How can we help you?
I have two models Locations and Vaccines that are related via a belongsToMany relationship using a pivot table inbetween. There is a model for the pivot called LocationVaccine and aside from the location_id and vaccine_id there is a piece of intermediate data "is_required" that is a boolean to state whether that vaccine is required (true), or just recommended (false) in that location.
Currently I am able to load and save Vaccines to a new or existing location no problem, however I am struggling to find a solution that will allow me to choose whether or not a selected vaccine is required or not. I am using a select at the moment with the ->pivotData() function where I can set "is_required" to true or false, but that is only at the top level of the select, not for each selected option.
The only solution I can think of right now is to introduce a second pivot and relationship between vaccines and have two different selects in my filament form, one that inserts into the existing pivot table for required vaccines and the new one that inserts into the new pivot and loads via the new relationship. I am sure this will work but it feels very "un-laravely" to have two pivots and relationships to track something that should be tracked with intermediate data on the single pivot table.
Has anyone any suggestions as to how I can achieve this? Maybe I'm using the wrong type of filament field that would make this much simpler?
Beta Was this translation helpful? Give feedback.
All reactions