Php 状态显示-隐藏产品-拉维
我需要创建一个if条件,其功能是根据产品是否可见来隐藏或显示产品 可见:1 隐藏:0 表已经创建,正如您所看到的,我只需要代码 我的代码:blade.phpPhp 状态显示-隐藏产品-拉维,php,laravel,laravel-5,Php,Laravel,Laravel 5,我需要创建一个if条件,其功能是根据产品是否可见来隐藏或显示产品 可见:1 隐藏:0 表已经创建,正如您所看到的,我只需要代码 我的代码:blade.php <div style="margin-top: 10px; " class="w-100"> @if(count($products)>0) @php $total = 0; @endphp @foreach($p
<div style="margin-top: 10px; " class="w-100">
@if(count($products)>0)
@php
$total = 0;
@endphp
@foreach($products as $product)
@php
$cart = \Session::get('cart');
$product_q = 0;
if ($cart) {
foreach ($cart as $item) {
if ($item->id == $product->id) {
$product_q = $item->quantity ?? 0;
$total = $total + ($product->price * $item->quantity);
}
}
}
if (is_numeric($product_q) == false) {
$product_q = 0;
}
@endphp
<div class="bg-dark tx-white h-100">
<ul class="list-group bordecero">
<li class="list-group-item bordecero bg-dark tx-white w-100">
<div class="col-12 p-0 d-flex justify-content-center align-items-center">
@if($category->show_img)
<div class="col-4">
@if(!empty($product->image))
<img style="height: auto;" class="w-100 shadow-sm bd img-fluid" src="{{ url($product->image) }}">
@else
<img style="height: auto;" class="w-100 shadow-sm bd img-fluid" src="http://placehold.it/700x400">
@endif
</div>
@endif
<div class="@if($category->show_img) col-8 @else col-12 @endif">
<h5> <a style="color: #fff;" href="{{ route('product-detail',['slug'=> $product->slug]) }}">{{$product->name}}</a><span class="badge badge-pill badge-light tx-dark ml-2 product-count-{{$product->id}}">{{$product_q}}</span>
</h5>
<h6>
<span style="color: #fff;" class="label label-success">${{ number_format($product->price,2) }}</span>
</h6>
<p style="color: #fff;">{{$product->description}}</p>
@if($product->destacado)
<span class="badge badge-pill badge-danger ">DESTACADO</span>
@endif
@php
$extras = App\Extra::where("product_id", $product->id)->first();
@endphp
@if(!empty($extras))
<a style="color: #2c2c2c;" href="{{ route('product-detail',['slug'=> $product->slug]) }}">
<span class="badge badge-pill badge-primary mb-4 ">+ AGREGADOS</span>
</a>
@else
<span class="badge badge-pill badge-primary mb-4">SIN AGREGADOS</span>
@endif
<div class="col-12 p-0 d-flex">
<input type="hidden" id="quantity-{{$product->id}}" data-slug="{{$product->slug}}" data-id="{{ $product->id }}" class="form-control select2 quantity" name="num_entregable" @if(isset($product_q)) value="{{$product_q}}" @else value="1" @endif min="1" required>
<button class="btn btn-danger mr-2 quantity-modify" data-quantity="quantity-{{$product->id}}" data-modify="add"> <b><i class="fas fa-plus"></i></b></button>
<button class="btn btn-danger quantity-modify" data-quantity="quantity-{{$product->id}}" data-modify="remove"> <b><i class="fas fa-minus"></i></b></button>
</div>
</div>
</div>
</li>
</ul>
</div>
@endforeach
<div style="z-index: 100;" class="pedidob mg-t-auto">
<a class="btn btn-danger btn-rounded btn-block tx-white d-flex justify-content-center" href="{{url('/cart/show')}}"><b>VER PEDIDO - <span class="total">{{$total}}</span>$</b></a>
</div>
</div>
@else
<div class="col-lg-12">
<div class="card h-100">
<div class="card-body">
<h4 class="card-title">
<a href="#">No hay productos</a>
</h4>
</div>
</div>
</div>
@endif
@如果(计数($产品)>0)
@php
$total=0;
@endphp
@foreach($products as$product)
@php
$cart=\Session::get('cart');
$product_q=0;
如果($cart){
foreach($cart作为$item){
如果($item->id==$product->id){
$product\U q=$item->数量??0;
$total=$total+($product->price*$item->quantity);
}
}
}
如果(是数字($product\U q)==false){
$product_q=0;
}
@endphp
-
@如果($category->show\u img)
@如果(!空($product->image))
图像)}}“>
@否则
@恩迪夫
@恩迪夫
{{$product_q}}
${{number_格式($product->price,2)}
{{$product->description}
@如果($product->destacado)
德斯塔卡多
@恩迪夫
@php
$extras=App\Extra::where(“product_id”,$product->id)->first();
@endphp
@如果(!空($extras))
@否则
阿格雷加多斯罪
@恩迪夫
@endforeach
@否则
@恩迪夫
我需要创建一个if条件,根据“可见”表显示或隐藏产品
请帮忙你能试试这个吗
@如果(计数($产品)>0)
@php
$total=0;
@endphp
@foreach($products as$product)
@php
$cart=\Session::get('cart');
$product_q=0;
如果($cart){
foreach($cart作为$item){
如果($item->id==$product->id){
$product\U q=$item->数量??0;
$total=$total+($product->price*$item->quantity);
}
}
}
如果(是数字($product\U q)==false){
$product_q=0;
}
@endphp
@如果($product->visible)
-
@如果($category->show\u img)
@如果(!空($product->image))
图像)}}“>
@否则
@恩迪夫
@恩迪夫
{{$product_q}}
${{number_格式($product->price,2)
}}
{{{$product->description}
@如果($product->destacado)
德斯塔卡多
@恩迪夫
@php
$extras=App\Extra::where(“product_id”,$product->id)->first();
@endphp
@如果(!空($extras))
@否则
阿格雷加多斯罪
@恩迪夫
@恩迪夫
@endforeach
@否则
@恩迪夫
您需要在foreach之后编写条件@if($product->visible==1),要排除设置为隐藏的产品,您可以在下面的代码中试用
<div style="margin-top: 10px; " class="w-100">
@if(count($products)>0)
@php
$total = 0;
@endphp
@foreach($products as $product)
@if($product->visible == 1)
@php
$cart = \Session::get('cart');
$product_q = 0;
if ($cart) {
foreach ($cart as $item) {
if ($item->id == $product->id) {
$product_q = $item->quantity ?? 0;
$total = $total + ($product->price * $item->quantity);
}
}
}
if (is_numeric($product_q) == false) {
$product_q = 0;
}
@endphp
<div class="bg-dark tx-white h-100">
<ul class="list-group bordecero">
<li class="list-group-item bordecero bg-dark tx-white w-100">
<div class="col-12 p-0 d-flex justify-content-center align-items-center">
@if($category->show_img)
<div class="col-4">
@if(!empty($product->image))
<img style="height: auto;" class="w-100 shadow-sm bd img-fluid" src="{{ url($product->image) }}">
@else
<img style="height: auto;" class="w-100 shadow-sm bd img-fluid" src="http://placehold.it/700x400">
@endif
</div>
@endif
<div class="@if($category->show_img) col-8 @else col-12 @endif">
<h5> <a style="color: #fff;" href="{{ route('product-detail',['slug'=> $product->slug]) }}">{{$product->name}}</a><span class="badge badge-pill badge-light tx-dark ml-2 product-count-{{$product->id}}">{{$product_q}}</span>
</h5>
<h6>
<span style="color: #fff;" class="label label-success">${{ number_format($product->price,2) }}</span>
</h6>
<p style="color: #fff;">{{$product->description}}</p>
@if($product->destacado)
<span class="badge badge-pill badge-danger ">DESTACADO</span>
@endif
@php
$extras = App\Extra::where("product_id", $product->id)->first();
@endphp
@if(!empty($extras))
<a style="color: #2c2c2c;" href="{{ route('product-detail',['slug'=> $product->slug]) }}">
<span class="badge badge-pill badge-primary mb-4 ">+ AGREGADOS</span>
</a>
@else
<span class="badge badge-pill badge-primary mb-4">SIN AGREGADOS</span>
@endif
<div class="col-12 p-0 d-flex">
<input type="hidden" id="quantity-{{$product->id}}" data-slug="{{$product->slug}}" data-id="{{ $product->id }}" class="form-control select2 quantity" name="num_entregable" @if(isset($product_q)) value="{{$product_q}}" @else value="1" @endif min="1" required>
<button class="btn btn-danger mr-2 quantity-modify" data-quantity="quantity-{{$product->id}}" data-modify="add"> <b><i class="fas fa-plus"></i></b></button>
<button class="btn btn-danger quantity-modify" data-quantity="quantity-{{$product->id}}" data-modify="remove"> <b><i class="fas fa-minus"></i></b></button>
</div>
</div>
</div>
</li>
</ul>
</div>
@endif
@endforeach
<div style="z-index: 100;" class="pedidob mg-t-auto">
<a class="btn btn-danger btn-rounded btn-block tx-white d-flex justify-content-center" href="{{url('/cart/show')}}"><b>VER PEDIDO - <span class="total">{{$total}}</span>$</b></a>
</div>
</div>
@else
<div class="col-lg-12">
<div class="card h-100">
<div class="card-body">
<h4 class="card-title">
<a href="#">No hay productos</a>
</h4>
</div>
</div>
</div>
@endif
@如果(计数($产品)>0)
@php
$total=0;
@endphp
@foreach($products as$product)
@如果($product->visible==1)
@php
$cart=\Session::get('cart');
$product_q=0;
如果($cart){
foreach($cart作为$item){
如果($item->id==$product->id){
$product\U q=$item->数量??0;
$total=$total+($product->price*$item->quantity);
}
}
}
如果(是数字($product\U q)==false){
$product_q=0;
}
@endphp
-
@如果($category->show\u img)
@如果(!空($product->image))
图像)}}“>
@否则
@恩迪夫
@恩迪夫
{{$product_q}}