When I write @foreach($products as $product)
it's destroying all html which is inside it and nothing appears.
Web Route code
Route::get('/product/tag/{tag}', [IndexController::class, 'TagWiseProduct']);
IndexController
public function TagWiseProduct($tag){
$products = Product::where('status',1)
->where('product_tags_en',$tag)
->where('product_tags_ar',$tag)
->orderBy('id','DESC')
->paginate(3);
$categories = Category::orderBy('category_name_en','ASC')->get();
return view('frontend.tags.tags_view',compact('products','categories'));
}
tags_view.blade page
<div class="search-result-container ">
<div id="myTabContent" class="tab-content category-list">
<div class="tab-pane active " id="grid-container">
<div class="category-product">
<div class="row">
@foreach($products as $product)
<div class="col-sm-6 col-md-4 wow fadeInUp">
<div class="products">
<div class="product">
<div class="product-image">
<div class="image"> <a href="{{ url('product/details/'.$product->id.'/'.$product->product_slug_en ) }}"><img src="{{ asset($product->product_thambnail) }}" alt=""></a> </div>
<!-- /.image -->
@php
$amount = $product->selling_price - $product->discount_price;
$discount = ($amount/$product->selling_price) * 100;
@endphp
<div>
@if ($product->discount_price == NULL)
<div class="tag new"><span>new</span></div>
@else
<div class="tag hot"><span>{{ round($discount) }}%</span></div>
@endif
</div>
<!-- /.product-image -->
<div class="product-info text-left">
<h3 class="name"><a href="{{ url('product/details/'.$product->id.'/'.$product->product_slug_en ) }}">
@if(session()->get('language') == 'arabic') {{ $product->product_name_ar }} @else {{ $product->product_name_en }} @endif</a></h3>
<div class="rating rateit-small"></div>
<div class="description"></div>
@if ($product->discount_price == NULL)
<div class="product-price"> <span class="price"> ${{ $product->selling_price }} </span> </div>
@else
<div class="product-price"> <span class="price"> ${{ $product->discount_price }} </span> <span class="price-before-discount">$ {{ $product->selling_price }}</span> </div>
@endif
<!-- /.product-price -->
</div>
<!-- /.product-info -->
<div class="cart clearfix animate-effect">
<div class="action">
<ul class="list-unstyled">
<li class="add-cart-button btn-group">
<button class="btn btn-primary icon" data-toggle="dropdown" type="button"> <i class="fa fa-shopping-cart"></i> </button>
<button class="btn btn-primary cart-btn" type="button">Add to cart</button>
</li>
<li class="lnk wishlist"> <a class="add-to-cart" href="detail.html" title="Wishlist"> <i class="icon fa fa-heart"></i> </a> </li>
<li class="lnk"> <a class="add-to-cart" href="detail.html" title="Compare"> <i class="fa fa-signal"></i> </a> </li>
</ul>
</div>
<!-- /.action -->
</div>
<!-- /.cart -->
</div>
<!-- /.product -->
</div>
<!-- /.products -->
</div>
<!-- /.item -->
@endforeach
</div>
<!-- /.row -->
</div>
<!-- /.category-product -->
</div>
<!-- /.tab-pane -->
<div class="tab-pane " id="list-container">
<div class="category-product">
@foreach($products as $product)
<div class="category-product-inner wow fadeInUp">
<div class="products">
<div class="product-list product">
<div class="row product-list-row">
<div class="col col-sm-4 col-lg-4">
<div class="product-image">
<div class="image"> <img src="{{ asset($product->product_thambnail) }}" alt=""> </div>
</div>
<!-- /.product-image -->
</div>
<!-- /.col -->
<div class="col col-sm-8 col-lg-8">
<div class="product-info">
<h3 class="name"><a href="{{ url('product/details/'.$product->id.'/'.$product->product_slug_en ) }}">
@if(session()->get('language') == 'arabic') {{ $product->product_name_ar }} @else {{ $product->product_name_en }} @endif</a></h3>
<div class="rating rateit-small"></div>
@if ($product->discount_price == NULL)
<div class="product-price"> <span class="price"> ${{ $product->selling_price }} </span> </div>
@else
<div class="product-price"> <span class="price"> ${{ $product->discount_price }} </span> <span class="price-before-discount">$ {{ $product->selling_price }}</span> </div>
@endif
<!-- /.product-price -->
<div class="description m-t-10"> @if(session()->get('language') == 'arabic') {{ $product->short_descp_ar }} @else {{ $product->short_descp_en }} @endif</div>
</div>
<div class="cart clearfix animate-effect">
<div class="action">
<ul class="list-unstyled">
<li class="add-cart-button btn-group">
<button class="btn btn-primary icon" data-toggle="dropdown" type="button"> <i class="fa fa-shopping-cart"></i> </button>
<button class="btn btn-primary cart-btn" type="button">Add to cart</button>
</li>
<li class="lnk wishlist"> <a class="add-to-cart" href="detail.html" title="Wishlist"> <i class="icon fa fa-heart"></i> </a> </li>
<li class="lnk"> <a class="add-to-cart" href="detail.html" title="Compare"> <i class="fa fa-signal"></i> </a> </li>
</ul>
</div>
<!-- /.action -->
</div>
<!-- /.cart -->
</div>
<!-- /.product-info -->
</div>
<!-- /.col -->
</div>
@php
$amount = $product->selling_price - $product->discount_price;
$discount = ($amount/$product->selling_price) * 100;
@endphp
<!-- /.product-list-row -->
<div>
@if ($product->discount_price == NULL)
<div class="tag new"><span>new</span></div>
@else
<div class="tag hot"><span>{{ round($discount) }}%</span></div>
@endif
</div>
</div>
<!-- /.product-list -->
</div>
<!-- /.products -->
</div>
<!-- /.category-product-inner -->
@endforeach
</div>
<!-- /.category-product -->
</div>
<!-- /.tab-pane #list-container -->
</div>
<!-- /.tab-content -->
<div class="clearfix filters-container">
<div class="text-right">
<div class="pagination-container">
<ul class="list-inline list-unstyled">
<li class="prev"><a href="#"><i class="fa fa-angle-left"></i></a></li>
<li><a href="#">1</a></li>
<li class="active"><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li class="next"><a href="#"><i class="fa fa-angle-right"></i></a></li>
</ul>
<!-- /.list-inline -->
</div>
<!-- /.pagination-container --> </div>
<!-- /.text-right -->
</div>
<!-- /.filters-container -->
</div>
<!-- /.search-result-container -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
My Answer:
means that I am using a foreach loop in PHP to iterate over an array of products. The $products variable contains the array of products, and $product is the variable that will hold each individual product during each iteration of the loop. This allows me to access and work with each product in the array one at a time.
Rate this post
5 of 5 based on 9227 votesComments