1
I’m using the Larable a few months ago and I came across the following problem of controlling stock after purchase automatically.
The logic of my system is this::
After purchasing a product in my store automatically decrease the amount selected by the user at the time of purchase, the system works correctly when there is only one item in the cart, when there are two items or more the system changes only one, my doubt is as it gets the code to recover and manipulate all the items through an array, follows the code:
php.blade.
@foreach($produtos as $produto)
...
Os valores a seguir estão dentro de um input, que são enviados por um formulário (acrescentei as [] em ambos).
<input type="hidden" name="id[]" value="{{ $produto['item']['id'] }}">
<input type="hidden" name="qtde[]" value="{{ $produto['quantidade'] }}">
...
@endforeach
Meucontroller.php my doubt is still in this file, I altered and it’s like this:
public function funcao(Request $request)
{
DB::table('produtos')
->where(['id', $request->get('id')])
->decrement(['quantidade', $request->get('qtde')]);
}
and as already expected returned the following error:
strtolower() expects Parameter 1 to be string, array Given
Shows the form inputs in full sff
– Miguel
The error is there you must send an array, name="id[]" and the same to the Qtd, after the server side you work it in a foreach
– Miguel
Okay, thanks for responding so quickly, could you give me some example of what the code looks like?
– jardel frank