Dependent MorphToSelect Field
I have 2
MorphToSelect
fields, is it possible to make the 2nd one dependable on the first one, like with the Select
field? I want to filter the values on the 2nd MorphToSelect
field based on the value select on the first MorphToSelect
field. I only want to filter the values and not the Type. I see there is the modifyOptionsQueryUsing
function on MorphToSelect\Type
, but not sure how to change the query based on another MorphToSelect
fields data.10 Replies
@awcodes appreciate if you have any insight on this. Something to learn for me today 🙂
Can you provide any code that you've tried?
Basically I am trying to load the package Type based on the vendor being selected. And show only the packages that belong to that vendor
I did see the documentation here https://filamentphp.com/docs/2.x/forms/fields#handling-morphto-relationships, but the use of
$this
inside the closure of the method modifyOptionsQueryUsing
throws an errorThis is the error I get when using
$this
on the closure
This is a lot to digest and really complicated. 🤣
where are you using $this
what for
I used
$this
as shown on the docs and got an error, but then switched the code to use the Closure
like I would use with the Select
field.
All I am trying to do is modify the query for the MorphToSelect
to filter the values it shows based on the previous MorphToSelect
the example isnt nessecary for admin resources specifically, which is why we use $this
so try
$get('vendor_id')
ok, let me try that. show I use the
_id
column of the morph there.
Perfect. That worked. I appreciate the help