Обновить товары в корзине (пакет -> darryldecode) Laravel 5.7 - PullRequest
0 голосов
/ 28 декабря 2018

Мой блейд-файл --->

{!! Form::open(['url'=>'/cart/update', 'method'=>'POST']) !!}
<div class="color-quality">
     <div class="color-quality-right">
     <input type="number" name="qty" value="{{ $cartProduct->quantity }}" min="1">
     <input type="hidden" name="id" value="{{ $cartProduct->id }}">
     <input type="submit" name="submit" value="update" class="item_add hvr-outline-out button2">
     {{-- <button type="submit" name="submit" value="update" class="item_add hvr-outline-out button2">Update</button> --}}
     </div>
     </div>
{!! Form::close() !!}

файл маршрута ->

Route::post('/cart/update', 'CartController@updateCart');

файл контроллера

public function updateCart(Request $request){
    $qty= $request->qty;
    $id = $request->id;

    /*echo $qty;
    echo "<br>";
    echo $id;*/
   Cart::update($id, $qty);
   return redirect('/cart/show');

}

когда я открою файл и нажму UPDATE btn, тогда я получу результат как с этим номером, так и с номером ... return , с другой стороны, получить ошибку ... ErrorException (E_WARNING) В foreach указан неверный аргумент ()

C: \ xampp \ htdocs \ larashop \ vendor \ darryldecode \ cart \ src \ Darryldecode \ Cart\ Cart.php * обновить корзину * * @param $ id * @param $ data * * $ data будет ассоциативным массивом, вам не нужно передавать все данные, только значение ключа * элемента, который выхотите обновить его * @return bool * / обновление публичной функции ($ id, $ data) {if ($ this-> fireEvent ('update', $ data) === false) {return false;}

    $cart = $this->getContent();

    $item = $cart->pull($id);

    foreach ($data as $key => $value) {
        // if the key is currently "quantity" we will need to check if an arithmetic
        // symbol is present so we can decide if the update of quantity is being added
        // or being reduced.
        if ($key == 'quantity') {
            // we will check if quantity value provided is array,
            // if it is, we will need to check if a key "relative" is set
            // and we will evaluate its value if true or false,
            // this tells us how to treat the quantity value if it should be updated
            // relatively to its current quantity value or just totally replace the value
            if (is_array($value)) {
                if (isset($value['relative'])) {
                    if ((bool)$value['relative']) {
                        $item = $this->updateQuantityRelative($item, $key, $value['value']);
                    } else {
                        $item = $this->updateQuantityNotRelative($item, $key, $value['value']);
                    }
                }
            } else {
                $item = $this->updateQuantityRelative($item, $key, $value);
            }

Аргументы "Недопустимый аргумент для foreach ()"

...