Fix 500 on product create: remove $arguments from render-time closures
Deploy / deploy (push) Successful in 15s
Deploy / deploy (push) Successful in 15s
In Filament v3, $arguments is only injected when an action is executed (clicked), not when it's rendered. Using $arguments in label(), icon(), color() and visible() closures causes ErrorException: Undefined variable $arguments on every Livewire update, including on the create page. Simplified extraItemAction to static label/icon/color; all dynamic logic (publish vs sync, guard for unsaved items) stays in action(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
74b47193d9
commit
9ef24fc45f
1 file changed
+8
-16
@@ -155,23 +155,18 @@ class ProductResource extends Resource {
|
||||
->addActionLabel('Option hinzufügen')
|
||||
->extraItemActions([
|
||||
FormAction::make('shopify')
|
||||
->label(fn (array $arguments, Repeater $component): string =>
|
||||
($component->getState()[$arguments['item']]['shopify_variant_id'] ?? null)
|
||||
? 'Shopify sync' : 'Zu Shopify'
|
||||
)
|
||||
->icon(fn (array $arguments, Repeater $component): string =>
|
||||
($component->getState()[$arguments['item']]['shopify_variant_id'] ?? null)
|
||||
? 'heroicon-o-arrow-path' : 'heroicon-o-arrow-up-tray'
|
||||
)
|
||||
->color(fn (array $arguments, Repeater $component): string =>
|
||||
($component->getState()[$arguments['item']]['shopify_variant_id'] ?? null)
|
||||
? 'info' : 'warning'
|
||||
)
|
||||
->label('Shopify')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('gray')
|
||||
->requiresConfirmation()
|
||||
->action(function (array $arguments, Repeater $component): void {
|
||||
$item = $component->getState()[$arguments['item']] ?? [];
|
||||
$sizeId = (int) ($item['product_size_id'] ?? 0);
|
||||
if (! $sizeId) {
|
||||
\Filament\Notifications\Notification::make()
|
||||
->title('Zuerst speichern')
|
||||
->warning()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
$page = $component->getContainer()->getLivewire();
|
||||
@@ -180,10 +175,7 @@ class ProductResource extends Resource {
|
||||
} else {
|
||||
$page->publishVariantToShopify($sizeId);
|
||||
}
|
||||
})
|
||||
->visible(fn (array $arguments, Repeater $component): bool =>
|
||||
! empty($component->getState()[$arguments['item']]['product_size_id'] ?? null)
|
||||
),
|
||||
}),
|
||||
])
|
||||
->afterStateHydrated(function ($state, $set, $record) {
|
||||
if ($record) {
|
||||
|
||||
Reference in new issue
Block a user