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')
|
->addActionLabel('Option hinzufügen')
|
||||||
->extraItemActions([
|
->extraItemActions([
|
||||||
FormAction::make('shopify')
|
FormAction::make('shopify')
|
||||||
->label(fn (array $arguments, Repeater $component): string =>
|
->label('Shopify')
|
||||||
($component->getState()[$arguments['item']]['shopify_variant_id'] ?? null)
|
->icon('heroicon-o-arrow-path')
|
||||||
? 'Shopify sync' : 'Zu Shopify'
|
->color('gray')
|
||||||
)
|
|
||||||
->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'
|
|
||||||
)
|
|
||||||
->requiresConfirmation()
|
->requiresConfirmation()
|
||||||
->action(function (array $arguments, Repeater $component): void {
|
->action(function (array $arguments, Repeater $component): void {
|
||||||
$item = $component->getState()[$arguments['item']] ?? [];
|
$item = $component->getState()[$arguments['item']] ?? [];
|
||||||
$sizeId = (int) ($item['product_size_id'] ?? 0);
|
$sizeId = (int) ($item['product_size_id'] ?? 0);
|
||||||
if (! $sizeId) {
|
if (! $sizeId) {
|
||||||
|
\Filament\Notifications\Notification::make()
|
||||||
|
->title('Zuerst speichern')
|
||||||
|
->warning()
|
||||||
|
->send();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$page = $component->getContainer()->getLivewire();
|
$page = $component->getContainer()->getLivewire();
|
||||||
@@ -180,10 +175,7 @@ class ProductResource extends Resource {
|
|||||||
} else {
|
} else {
|
||||||
$page->publishVariantToShopify($sizeId);
|
$page->publishVariantToShopify($sizeId);
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
->visible(fn (array $arguments, Repeater $component): bool =>
|
|
||||||
! empty($component->getState()[$arguments['item']]['product_size_id'] ?? null)
|
|
||||||
),
|
|
||||||
])
|
])
|
||||||
->afterStateHydrated(function ($state, $set, $record) {
|
->afterStateHydrated(function ($state, $set, $record) {
|
||||||
if ($record) {
|
if ($record) {
|
||||||
|
|||||||
Reference in new issue
Block a user