Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想使用laravel在产品的列状态全部等于零时隐藏html代码_Laravel - Fatal编程技术网

我想使用laravel在产品的列状态全部等于零时隐藏html代码

我想使用laravel在产品的列状态全部等于零时隐藏html代码,laravel,Laravel,我试图隐藏的html代码,如果条件时,所有产品的特点是零,html代码不应该显示在头版请帮助我如何才能做到这一点 控制器 public function index() { $data = [ 'products' => Product::with('productColorGallary')->where('is_featured', 1)->first(), ]; return view('home', $data); }

我试图隐藏的html代码,如果条件时,所有产品的特点是零,html代码不应该显示在头版请帮助我如何才能做到这一点

控制器

public  function index()
{



$data = [

    'products' => Product::with('productColorGallary')->where('is_featured', 1)->first(),
   
      ];

   return view('home', $data);
 }
html视图

   @if($products->is_featured  == 0)
        <div class="col-md-6">
          <div class="new-wall-image">
            <img src="{{config('wall_master_furishing.file_url').$products->productColorGallary->featured_image}}" alt="">
          </div>
        </div>
        <div class="col-md-6">
          <div class="new-wall-descp">
            <h2 class="theme-title">New Walls
            </h2>
            <p>{!!$products->description!!}</p>
            <a class="blue-btn-a" href="#">Read More
              <i class="fa fa-angle-right">
              </i>
            </a>
          </div>
        </div>
        @endif
@if($products->is_featured==0)
productColorGallary->特色图片}“alt=”“>
新墙
{!!$products->description!!}

@恩迪夫
Products是一个数组键,因此您可以使用$data['Products'等。。 但是,如果您创建一个集合/对象(如以下所示),则应该可以:

公共功能索引()
{
//first将从db返回第一个匹配的项
//您将只得到is_=1
$products=Product::with('productColorGallary')->其中('is_characterized',1)->first();
返回视图(“主视图”、紧凑型(“产品”);
}

Products是一个数组键,因此您可以使用$data['Products'等。。 但是,如果您创建一个集合/对象(如以下所示),则应该可以:

公共功能索引()
{
//first将从db返回第一个匹配的项
//您将只得到is_=1
$products=Product::with('productColorGallary')->其中('is_characterized',1)->first();
返回视图(“主视图”、紧凑型(“产品”);
}

您在数据库中获得的产品具有is_featured=1。这意味着您的刀片服务器中的if条件将始终为false

另外,你是想得到所有的产品还是一个? 如果有很多,那么:

你的控制器

public  function index()
{



$data = [

    'products' => Product::with('productColorGallary')->where('is_featured', 1)->first(),
   
      ];

   return view('home', $data);
 }
公共功能索引()
{
$products=Product::with('productColorGallary')->get();
返回视图(“主视图”、紧凑型(“产品”);
}
还有你的刀锋

@foreach($products as $product)
    @if($product->is_featured  == 0)
        <div class="col-md-6">
          <div class="new-wall-image">
            <img src="{{config('wall_master_furishing.file_url').$product->productColorGallary->featured_image}}" alt="">
          </div>
        </div>
        <div class="col-md-6">
          <div class="new-wall-descp">
            <h2 class="theme-title">New Walls
            </h2>
            <p>{!!$products->description!!}</p>
            <a class="blue-btn-a" href="#">Read More
              <i class="fa fa-angle-right">
              </i>
            </a>
          </div>
        </div>
    @else
      SOMETHING HERE IF PRODUCT IS FEATURED
    @endif
     SOMETHING HERE COMMONS TO BOTH FEATURED AND NOT FEATURED

@endforeach
@foreach($products作为$product)
@如果($product->is_特色==0)
productColorGallary->特色图片}“alt=”“>
新墙
{!!$products->description!!}

@否则 如果产品是特色产品,请点击此处 @恩迪夫 这里有些东西既有特色又没有特色 @endforeach
您在数据库中获得的产品具有is_featured=1。这意味着您的刀片服务器中的if条件将始终为false

另外,你是想得到所有的产品还是一个? 如果有很多,那么:

你的控制器

public  function index()
{



$data = [

    'products' => Product::with('productColorGallary')->where('is_featured', 1)->first(),
   
      ];

   return view('home', $data);
 }
公共功能索引()
{
$products=Product::with('productColorGallary')->get();
返回视图(“主视图”、紧凑型(“产品”);
}
还有你的刀锋

@foreach($products as $product)
    @if($product->is_featured  == 0)
        <div class="col-md-6">
          <div class="new-wall-image">
            <img src="{{config('wall_master_furishing.file_url').$product->productColorGallary->featured_image}}" alt="">
          </div>
        </div>
        <div class="col-md-6">
          <div class="new-wall-descp">
            <h2 class="theme-title">New Walls
            </h2>
            <p>{!!$products->description!!}</p>
            <a class="blue-btn-a" href="#">Read More
              <i class="fa fa-angle-right">
              </i>
            </a>
          </div>
        </div>
    @else
      SOMETHING HERE IF PRODUCT IS FEATURED
    @endif
     SOMETHING HERE COMMONS TO BOTH FEATURED AND NOT FEATURED

@endforeach
@foreach($products作为$product)
@如果($product->is_特色==0)
productColorGallary->特色图片}“alt=”“>
新墙
{!!$products->description!!}

@否则 如果产品是特色产品,请点击此处 @恩迪夫 这里有些东西既有特色又没有特色 @endforeach
ErrorException尝试获取非对象的属性'is_-featured'(视图:/home/zubair/htdocs/wallmasterfinding.com/web/resources/views/home.blade.php)尝试此
firstOrFail()
Product::with('productColorGallary')->其中('is_-featured',1)->firstOrFail()is this>ErrorException试图获取非对象的属性'is_featured'(视图:/home/zubair/htdocs/wallmasterfinding.com/web/resources/views/home.blade.php)试试这个
firstOrFail()
like
Product::with('productColorGallary')->where('is_featured',1)->firstOrFail()
这是不是>在返回之前尝试获取非对象(View:/home/zubair/htdocs/wallmasterfinding.com/web/resources/views/home.blade.php)的属性“is_characterized”,您应该编写dd($product);并且您可能会看到它的特征:1和此条件
@if($products->is_characterized==0)
不起作用。但是
@if-featured==0@else//当feature为1或任何其他@endif
时应该起作用。尝试获取非对象的属性“is_-featured”(View:/home/zubair/htdocs/wallmasterfinding.com/web/resources/views/home.blade.php)在返回之前应该写dd($product);您可能会看到它的特色:1,而此条件
@if($products->is_characterized==0)
不起作用。但是
@if characterized==0@else//当特色为1或任何其他@endif
时应该起作用。