How to have a default() for a Select multiple() ?
Hi, I have Select->multiple() and I can't initialize a default value. So what is necessary for inserting a default value ? The id ?
19 Replies
You need to pass an array:
default([2,3,4,10])
Noting default only works on creation not edit.
Ok, so I don't understand where is my problem π¦
This is the input
There is 1 result from this request but I can't make it an array
This is on a creation right? And when you remove dd you replace it with return ?
Yep
You have't fetchted the id's it should return an array of id's.
And the thing I noticed is that when I dd the result of the Eloquent query I have the 1 id, the one I want to use but when I do
I have every record in the DB table
so that DD should return: [single_id]
Yep
As an example to test the logic, if you replace: ->default([3]) does it work?
Yep, it select the third value of the Select by default
So I tried to format the id I have from the Elouqnt query but I don't know why it give me every record in an array as a result when I use pluck
It make no sense
Like its doing a new query
To give you more context, here is the options I have from the relationship on the select
When I do
I have as a result
Which is exactly what I am expecting
but this 4 can't be passed in the default like that because its not an array
So from this what would you do ?
That's a single integer you need to cast it to an array so:
return [Speciality::where('name', Filament::getTenant()->teamSpeciality->name)->first()?->id];
Hmm ... π
It works ofc
I don't know why I didn't think of that
haha
I was doing some weird thing with pluck toArray etc
π
because you were too fixated on the query π programmers tunnel vision, it's why asking questions or going for a walk helps π
Yep, thanks a lot π