Multi-Select Relationship by Image / Visually
I have a model:
How can I give the same same experience/results as a mulit-select \Forms\Components\Select() BUT with images rather than a text dropdown. In short I need the user to be able to search for images and select them to assign many artwork images to a single exhibition. Should I but using select? or maybe a RelationManager is better? Would love some advice please My latest attempt is with a relation-manager but that attempts to create new artwork which I don't want...I need to assign many artworks, visually to a parent exhibition.
Exhibition
which can have many Models: Artwork
How can I give the same same experience/results as a mulit-select \Forms\Components\Select() BUT with images rather than a text dropdown. In short I need the user to be able to search for images and select them to assign many artwork images to a single exhibition. Should I but using select? or maybe a RelationManager is better? Would love some advice please My latest attempt is with a relation-manager but that attempts to create new artwork which I don't want...I need to assign many artworks, visually to a parent exhibition.
22 Replies
Maybe it can help you
https://filamentphp.com/tricks/render-html-in-select-options
Filament
Render HTML in select options by Matthew Ost - Tricks - Filament
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
hmmm, trying that out now
I was going okay...but then when using multi-select hooked up to a reactive select I get some weirdness. Still pursuing, but currently when the select window looses focus, all of the previously selected items lose their styling and revert to text IDs.
Sadly I cannot get this to work with
Select()->multiple()
based on a parent Select()->reactive()
field When the reactive select is changed...all of the previously selected images in the select box turn to ID numbers...losing their styling. I though maybe I could retain the formatted state of the Select input by storing the IDs in a static property outside of the form()
and simply merge the IDs and re-query them to always return their data, but it's a big fat miss.Is you multiple select a relationship.?
I wonder if this could be handled with a relation-manager? But a relation-manager is more for creating new but related records. I am only interested in building relationhips but NOT creating anything new
Yes, ->multiple() is a necessity
Better question what is the code for the related select?
Let me pull out all of my static var nonsense or your head will explode...give me a minute
Make sure you are using
getOptionLabelsUsing
and not getOptionLabelUsing
. The "s" at the end matters when using multipleoh dang, let me see if there is magic in that "s"
@kennethsese nope, that made the whole thing error out when changing the reactive() select.
Here is what I have so far:
When using that you need to use $values which is an array
so like this (adapt as necesary):
->getOptionLabelsUsing(fn ($values): array => YourModel::find($values)?->pluck('name', 'id')
@kennethsese okay I see, thanks. Now what happens is the entire Select field resets and clears out (blank) after the parent/reactive select is changed.
Maybe I can try using that static property holding the collection again
Won't your child options change when your parent changes?
Good question? This is a multiselect so i was hoping they dont
So you want to pick a Parent A and Child A1 and A2 and then be able to swtich to Parent B and then choose B1 and B2, but also keep A1 and A2?
Maybe this is a many to many?
I actually set up a pivot table originally and am not opposed to that for sure.
The reason I moved away from the pivot table idea was because the relation manager seems to only allow for creating...not asigning
but I am wide open for ideas!
You can totally attach relationships using a relation manager.
You can create too, but also attach/detach
I just need a way to 1) select > artist 2) select artworks associated with that artist 3) attach to the parent model: Exhibition and it needs to be visually based cannot be text only
Filament
Relation managers - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
yeah...im into it
hot damn...when you think you've seen it all
These fandangled Filamentors have done gone thought of everything - lol
I was barking way to loudly up the wrong tree
You should be able to customize the RM attach select to make it visual as well.
That's not to say you couldn't keep going down your select field path...you probably could. I think it just depends on how you want it to function. But a RM is probably going to be a lot eaiser
I like the RM path and it's the one I originally planned on taking because then the artwork can be sorted or clicked through for further actions
The docs mention that you must use
->withPivot()
is that deprecated advice?No. WithPivot is not deprecated.
It forces your relationship to append the pivot data onto the record with a join.
Making it accessible as attributes on the model.
Yes! The pivot table + relation-manager was indeed the way to go...I added integrated the select/html code (from above) and it works like magic. The second select simply becomes $action->getRecordSelect() . thanks guys