I tried to follow but still got the error
Call to undefined method Illuminate \ Database \ Query \ Builder :: firstOrFail()
Query Builder does not have the firstOrFail(); method, it's only available to Eloquent models, for example if tbl_product was a Product model then it would be:
firstOrFail();
tbl_product
Product
$product_info = Product::where('product_id', $productId)->firstOrFail();
If you want to use Query Builder, then you could do the following:
$product_info = DB::table('tbl_product')->where('product_id', $productId)->first(); if ($product_info === null) throw \Exception('Product not found');
In Eloquent model you have to use firstOrFail method
firstOrFail
$product_info = Product::where('product_id'=>$productId)->firstOrFail();
Or you have to use
$product_info = Product::where('product_id'=>$productId)->first();
Copyright © 2021 Jogjafile Inc.
Query Builder does not have the
firstOrFail();method, it's only available to Eloquent models, for example iftbl_productwas aProductmodel then it would be:If you want to use Query Builder, then you could do the following: