I am getting this error:
ArgumentCountError Too few arguments to function Darryldecode\Cart\Cart::updateQuantityRelative(), 1 passed in ..\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 261 and exactly 3 expected (View: ...\resources\views\cart.blade.php)
cart.blade.php
@foreach(\Cart::session(auth()->id())->getContent() as $items)
<tr>
<td class="text-center">
<a href="{{ route('cart.destroy', $items->id)}}">x</a>
</td>
<td data-title="Product">
<a href="#" class="text-gray-90">{{ $items ['name'] }}</a>
</td>
<td data-title="Price">
<span class="">LKR {{ $items ['price'] }}.00</span>
</td>
<td data-title="Quantity">
<span class="sr-only">Quantity</span>
<!-- Quantity -->
<div class="border rounded-pill py-1 width-122 w-xl-80 px-3 border-color-1">
<div class="js-quantity row align-items-center">
<div class="col">
<input class="js-result form-control h-auto border-0 rounded p-0 shadow-none" type="text" value="{{ \Cart::updateQuantityRelative($items->quantity) }}">
</div>
<div class="col-auto pr-1">
<a class="js-minus btn btn-icon btn-xs btn-outline-secondary rounded-circle border-0" href="javascript:;">
<small class="fas fa-minus btn-icon__inner"></small>
</a>
<a class="js-plus btn btn-icon btn-xs btn-outline-secondary rounded-circle border-0" href="javascript:;">
<small class="fas fa-plus btn-icon__inner"></small>
</a>
</div>
</div>
</div>
<!-- End Quantity -->
</td>
<td data-title="Total">
<span class="">
{{ $items -> getPriceSum()}}
</span>
</td>
</tr>
@endforeach
CartController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
use App\Category;
use Darryldecode\Cart\Cart;
class CartController extends Controller
{
public function index()
{
return view ('cart');
}
public function show($id)
{
$product = Product::find($id);
return view('cart')->with(compact('product'));
}
public function destroy($itemId)
{
return back();
}
public function addtocart(Product $product)
{
\Cart::session(auth()->id())->add(array(
'id' => $product->id,
'name' => $product->prod_name,
'price' => $product->prod_price,
'quantity' => 1,
'attributes' => array(),
'associatedModel' => $product
));
return redirect()->back();
}
}
I installed Darryldecode shopping cart package.
This updateQuantityRelative
function is defined in it.
public function updateQuantityRelative($item, $key, $value)
{
if (preg_match('/\-/', $value) == 1) {
$value = (int)str_replace('-', '', $value);
// we will not allowed to reduced quantity to 0, so if the given value
// would result to item quantity of 0, we will not do it.
if (($item[$key] - $value) > 0) {
$item[$key] -= $value;
}
} elseif (preg_match('/\+/', $value) == 1) {
$item[$key] += (int)str_replace('+', '', $value);
} else {
$item[$key] += (int)$value;
}
return $item;
}
I think the below code is to be corrected. How it should be?
value="{{ \Cart::updateQuantityRelative($items->quantity) }}