Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!