CartController.php
public function store(Request $request)
{
$this->validate($request, [
'prod_id' => 'required|numeric',
'amount' => 'required|numeric|min:1',
'prod_type' => 'nullable'
]);
$exist = Cart::where('prod_id', request('prod_id'))->where('prod_type', request('prod_type'))->where('user_id', auth()->user()->user_id)->first();
if (empty($exist)) {
if (Products::checkStockAvailability(request('prod_id'), request('amount'))) {
Cart::create([
'user_id' => auth()->user()->user_id,
'prod_id' => request('prod_id'),
'amount' => request('amount'),
'prod_type' => request('prod_type'),
]);
} else {
flash('Pembelian melebihi jumlah stock yang tersedia')->error();
return back();
}
} else {
if (Products::checkStockAvailability(request('prod_id'), request('amount') + $exist->amount)) {
Cart::where('cart_id', $exist->cart_id)->update([
'amount' => $exist->amount + request('amount')
]);
} else {
flash('Pembelian melebihi jumlah stock yang tersedia')->error();
return back();
}
}
flash('Product dimasukkan ke dalam keranjang belanja');
return back();
}
Then, it must be this one. Only request being passed.
I think I see some light. The add product only works through product details since you have select the t-shirt size. It does not work through the frontpage for some reason. since you only know the product_id and not the product_type (small, medium, large, x-large).
Any idea how to solve this problems?
Someone mentioned to create a pop up when you click the product picture asking to fill in the t-shirt size. How to create pop up like this?