BadMethodCallException Call to undefined method App\Product::getProductStock() This error occurred while accessing the model function in controller
My Controller
$user_id = Auth::user()->id;
$user_email = Auth::user()->email;
// To prevent out of stock material from ordering
$userCart=DB::table('cart')->where('user_email',$user_email)->get();
// echo "<pre>"; print_r($userCart); die;
foreach ($userCart as $cart) {
$product_stock= Product:: getProductStock($cart->product_id,$cart->size);
echo $product_stock;
if ($product_stock==0) {
return redirect('/cart')->with('flash_message_error','Product is Stock sold out. Buy another product');
}
if ($Cart->quantity>$product_stock) {
return redirect('/cart')->with('flash_message_error','Reduced product stock & Try Again');
}
}
Model
public static function getProductStock($product_id,$product_size)
{
$getProductStock=ProductsAttribute::select('stock')->where(['product_id'=>$product_id,'size'=>$product_size])->first();
return $getProductStock->stock;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire