Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
Livewire invalid arrow-function arguments on action

I'm testing out Livewire with a Laravel shopping cart plugin. To add items to the cart you call a function, passing in id, name, quantity, price, and an optional array of metadata:

<button wire:click.prevent="addToCart('{{ $id }}', '{{ $product_name}}', 1, {{ $price }}, ['size' => '{{ $size }}'])">Add to Cart</button>

The rendered HTML looks perfect, but when I click the button I get:

Uncaught SyntaxError: invalid arrow-function arguments (parentheses around the arrow-function may help)

It doesn't seem to like the => in the array assignment. Does anyone know a fix?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

there is no such thing as an associative array in javascript, it's an object and as such you need to provide a valid object (if you still want it with the same structure).

<button wire:click.prevent="addToCart('{{ $id }}', '{{ $product_name}}', 1, {{ $price }}, {{json_encode(['size' => $size ])}})">Add to Cart</button>

or

 @json(['size' => $size ]) //instead of {{json_encode(['size' => $size ])}}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda