Using multi-select does not working when using it inside an Action

Hello, I have a table header action with multi-select, when I choose multiple options and press submit, then after submit $data array is empty Any ideas how to debug this or what I am doing wrong?
->headerActions([
Tables\Actions\Action::make('doors_to_add')
->label('Search and add')
->form([
Select::make('selected_doors')
->relationship('door', 'name', function ($query) {
$query->where('company_id', Filament::getTenant()->id)
->where('facility_id', $this->getOwnerRecord()->facility_id)
->whereNotIn('doors.id', $this->getOwnerRecord()->doors->pluck('door_id')->toArray());
})
->searchable(['name'])
->preload()
->multiple()
->required(),
])
->mutateFormDataUsing(function (array $data) {
\Log::info('Form data before action: '.print_r($data, true));

return $data;
})
->action(function (array $data) {
dd($data, request()->all());
}),
])
->headerActions([
Tables\Actions\Action::make('doors_to_add')
->label('Search and add')
->form([
Select::make('selected_doors')
->relationship('door', 'name', function ($query) {
$query->where('company_id', Filament::getTenant()->id)
->where('facility_id', $this->getOwnerRecord()->facility_id)
->whereNotIn('doors.id', $this->getOwnerRecord()->doors->pluck('door_id')->toArray());
})
->searchable(['name'])
->preload()
->multiple()
->required(),
])
->mutateFormDataUsing(function (array $data) {
\Log::info('Form data before action: '.print_r($data, true));

return $data;
})
->action(function (array $data) {
dd($data, request()->all());
}),
])
Solution:
It's because you have set it as a relationship, all relationships are removed from data.
Jump to solution
4 Replies
humunuk
humunukOP2mo ago
in dd(request()->all()) the data is present
array:2 [▼ // app/Filament/Resources/AccessGroupResource/RelationManagers/DoorsRelationManager.php:46
"_token" => "Tkf6ge5fVrBJapiLJE9IDc7A1GfLKY9rm0goNpoq"
"components" => array:1 [▼
0 => array:3 [▼
"snapshot" => "{"data":{"ownerRecord":[null,{"class":"App\\Models\\AccessGroup","key":1,"s":"mdl"}],"pageClass":"App\\Filament\\Resources\\AccessGroupResource\\Pages\\EditAcce

"
"updates" => array:2 [▼
"mountedTableActionsData.0.selected_doors.0" => "1"
"mountedTableActionsData.0.selected_doors.1" => "3"
]
"calls" => array:1 [▼
0 => array:3 [▶]
]
]
]
]
array:2 [▼ // app/Filament/Resources/AccessGroupResource/RelationManagers/DoorsRelationManager.php:46
"_token" => "Tkf6ge5fVrBJapiLJE9IDc7A1GfLKY9rm0goNpoq"
"components" => array:1 [▼
0 => array:3 [▼
"snapshot" => "{"data":{"ownerRecord":[null,{"class":"App\\Models\\AccessGroup","key":1,"s":"mdl"}],"pageClass":"App\\Filament\\Resources\\AccessGroupResource\\Pages\\EditAcce

"
"updates" => array:2 [▼
"mountedTableActionsData.0.selected_doors.0" => "1"
"mountedTableActionsData.0.selected_doors.1" => "3"
]
"calls" => array:1 [▼
0 => array:3 [▶]
]
]
]
]
Solution
toeknee
toeknee2mo ago
It's because you have set it as a relationship, all relationships are removed from data.
toeknee
toeknee2mo ago
I beleive you can add dehydrate to add it to data according to a post Im saw recenty.
humunuk
humunukOP2mo ago
awesome thank you 🙂 Adding ->dehydrated() makes it work, I am not sure it works as expected though
Want results from more Discord servers?
Add your server