© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
10 replies
Sayy

Error when select data with afterstateupdated

after find for select data with afterstateupdated and then error $price null, but my data not null on database.



protected function getFormSchema(): array
{
return [
Select::make('selectedProduct')
->label('Select Product')
->searchable()
->preload()
->options(Product::pluck('name', 'id')->toArray())
->live()
->afterStateUpdated(function ($state) {
$product = Product::find($state);
$this->record->orderDetails()->updateOrCreate(
[
'order_id' => $this->record->id,
'product_id' => $state,
],
[
'product_id' => $state,
'quantity' => $this->quantityValue,
'price' => $product->price,
'subtotal' => $product->price * $this->quantityValue,
]
);
}),
];
}
image.png
Solution
From as much as I understand, This simple if condition will solve your problem.
  ->afterStateUpdated(function ($state) {
                    if($state){
                    $product = Product::find($state);
                    $this->record->orderDetails()->updateOrCreate(
                        [
                            'order_id' => $this->record->id,
                            'product_id' => $state,
                        ],
                        [
                            'product_id' => $state,
                            'quantity' => $this->quantityValue,
                            'price' => $product->price,
                            'subtotal' => $product->price * $this->quantityValue,
                        ]
                    );
                    }
                }),
  ->afterStateUpdated(function ($state) {
                    if($state){
                    $product = Product::find($state);
                    $this->record->orderDetails()->updateOrCreate(
                        [
                            'order_id' => $this->record->id,
                            'product_id' => $state,
                        ],
                        [
                            'product_id' => $state,
                            'quantity' => $this->quantityValue,
                            'price' => $product->price,
                            'subtotal' => $product->price * $this->quantityValue,
                        ]
                    );
                    }
                }),
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Fill select and select a value with afterStateUpdated
FilamentFFilament / ❓┊help
3y ago
multiple() select not work with afterStateUpdated
FilamentFFilament / ❓┊help
2y ago
Using both afterStateUpdated AND afterStateUpdatedJs
FilamentFFilament / ❓┊help
8mo ago