Slide 137
Slide 137 text
Product Controller
/**
* Display the specified resource.
*
* @param string $slug
* @return \Illuminate\Http\Response
*/
public function show($slug)
{
$product = Product::where('slug', '=', $slug)->get()->first();
if (empty($product)) {
return response()->json([
'message' => 'Product not found',
], 404);
}
// check product is in stock
if ($product->quantity <= 0) {
return response()->json([
'message' => 'Product not in stock',
], 200);
}
return response()->json($product);
}