500 (Внутренняя ошибка сервера) - Изменить количество - Корзина в Laravel - PullRequest
0 голосов
/ 01 мая 2020

Для проекта я иду по курсу https://youtu.be/_MX0Dvfth_c?t=582, чтобы изменить количество в моей корзине для покупок с Laravel.

Я получаю 500 (внутренний сервер ошибка), когда я изменяю количество моего продукта.

РЕДАКТИРОВАТЬ: я использую библиотеку Ax ios, чтобы сделать AJAX запрос

код на мой взгляд "cart.blade. php "секция:


<select class="quantity" data-id="{{ $item->rowId }}" data-productQuantity="{{ 
   $item->model->quantity }}">
   @for ($i = 1; $i < 5 + 1 ; $i++)
   <option {{ $item->qty == $i ? 'selected' : '' }}>{{ $i }}</option>
   @endfor
</select>

@section('extra-js')
  <script src="{{ asset('js/app.js') }}"></script>
  <script>
    (function(){
      const classname = document.querySelectorAll('.quantity')

      Array.from(classname).forEach(function(element) {
        element.addEventListener('change', function() {
          const id = element.getAttribute('data-id')
          axios.patch(`/cart/${id}`, {
            quantity: this.value
          })
          .then(function (response) {
            console.log(response);
          })
          .catch(function (error) {
            console.log(error);
          });
        })
      })
    })();

  </script>
@endsection

Контроллер:


public function update(Request $request, $id)
    {
        Cart::update($id, $request->quantity);

        return response()->json(['success' => true]);
    }

Маршрут:

Route::patch('/cart/{product}', 'CartController@update')->name('cart.update');

Журнал:

app.js:285 PATCH http://xxx/cart/027c91341fd5cf4d2579b49c4b6a90da 500 (Internal Server Error)

dispatchXhrRequest  @   app.js:285
xhrAdapter  @   app.js:119
dispatchRequest @   app.js:765
Promise.then (async)        
request @   app.js:542
Axios.<computed>    @   app.js:567
wrap    @   app.js:1131
(anonymous) @   cart:158
ListPicker._handleMouseUp

Laravel Журнал

[2020-05-01 19:12:39] local.ERROR: Serialization of 'Closure' is not allowed {"exception":"[object] (Exception(code: 0): Serialization of 'Closure' is not allowed at C:\\laragon\\www\\projet-site-e-commerce-b2\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Store.php:129)

Я не знаю, где я допустил ошибку ... если кто-то может мне помочь!

Спасибо.

...