F
Filament12mo ago
Eth

issue with pluck() on array

I’m trying to display a list of options according to the place name from database (option from options -json- as you could see in the image) But it’s showing me the error message “Call to a member function pluck() on array” Code:
Forms\Components\Select::make('placeName')
->label('Place Name')
->required()
->live()
->searchable()
->options(Place::all()->pluck('placeName'))
->afterStateUpdated(function ($state, callable $set, callable $get){
$place = $get('placeName');
$placePrice = Place::find($place)->placePrice;
$placeOptions = Place::find($place)?->options->pluck('option');
$set('totalPrice', $placePrice);
$set('options', $placeOptions);
})
Forms\Components\Select::make('placeName')
->label('Place Name')
->required()
->live()
->searchable()
->options(Place::all()->pluck('placeName'))
->afterStateUpdated(function ($state, callable $set, callable $get){
$place = $get('placeName');
$placePrice = Place::find($place)->placePrice;
$placeOptions = Place::find($place)?->options->pluck('option');
$set('totalPrice', $placePrice);
$set('options', $placeOptions);
})
No description
2 Replies
Lara Zeus
Lara Zeus12mo ago
you cant pluck from array
$placeOptions = Place::find($place)?->options;
// check if not null
$getPlaceOptions = collect($placeOptions)->pluck('option');
$placeOptions = Place::find($place)?->options;
// check if not null
$getPlaceOptions = collect($placeOptions)->pluck('option');
Eth
EthOP12mo ago
Indeed, wrote it this way and it worked
->options(function ($state, callable $set, callable $get) {
$place = Place::find($get('placeName'));
if ($place) {
$placeOptions = $place->options;
if ($placeOptions) {
$getPlaceOptions = collect($placeOptions)->pluck('option');
return $getPlaceOptions;
}
}
return null;
})
->options(function ($state, callable $set, callable $get) {
$place = Place::find($get('placeName'));
if ($place) {
$placeOptions = $place->options;
if ($placeOptions) {
$getPlaceOptions = collect($placeOptions)->pluck('option');
return $getPlaceOptions;
}
}
return null;
})
Thank you!
Want results from more Discord servers?
Add your server