julzybae's avatar

Sending JS array via AJAX to laravel not working

I want to add data to the transaction and transaction_product tables in one form, but when I try the program code above there is an error message "The products must be an array." how should I deal with this?

Route

Route::post('/store-transaction', [App\Http\Controllers\TransactionController::class, 'store'])->name('transactions.store');

Controller:

HTML:

Script on blade:

0 likes
2 replies
jlrdw's avatar

What does the network request and response tabs show? Use them to tweak code as needed.

Also after:

 $products = json_decode($request->products, true);

Do a dd and see what the network tab shows. but the comma with true should be an array.

Have you tried without using JSON.stringify(products)?

1 like
julzybae's avatar
julzybae
OP
Best Answer
Level 1

@jlrdw Thanks for the suggestion, I've tried to fix it and it works. This is the program code that I have corrected:

1 like

Please or to participate in this conversation.