I work by ecommerce
site, and I want to test the quantity
of product
(annonce), if the qty = 0
display Not Avialable
in danger color, if qty <= 5
display low Stock
in color if qty > 5
display in Stock
in success color.
in my example it displays in my html code page.
AnnoncesController.php
public function show($id)
{
$annonces = Annonce::where('id',$id)->firstOrfail();
$mightAlsoLike = Annonce::where('id', '!=', $id)->mightAlsoLike()->get();
if( $annonces->quantity > setting('site.stock_threshold') ){
$stockLevel = '<div class="badge badge-pill badge-success">in stock</div>';
} elseif($annonces->quantity <= setting('site.stock_threshold') && $annonces->quantity > 0) {
$stockLevel = '<div class="badge badge-pill badge-warning">low stock</div>';
}else {
$stockLevel = '<div class="badge badge-pill badge-danger">Not Avialable</div>';
}
return view('annonces.details')->with([
'annonces' => $annonces,
'stockLevel' => $stockLevel,
'mightAlsoLike' => $mightAlsoLike
]);
}
details.blade.php
<div>{{ $stockLevel }}</div>