Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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

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
Php 如果else语句不起作用,则使用laravel筛选器_Php_Laravel_Laravel 5.4 - Fatal编程技术网

Php 如果else语句不起作用,则使用laravel筛选器

Php 如果else语句不起作用,则使用laravel筛选器,php,laravel,laravel-5.4,Php,Laravel,Laravel 5.4,我试图过滤我的产品的价格性别颜色 这是我使用类似url localhost/category/tag?price=100时的工作代码 if (request()->has('gender')) { $products = Product::withAllTags($tags)->where('gender', request('gender'))->get(); } if (request()->has('price')) { $product

我试图过滤我的产品的价格性别颜色 这是我使用类似url localhost/category/tag?price=100时的工作代码

if (request()->has('gender')) {
     $products = Product::withAllTags($tags)->where('gender', request('gender'))->get();
  }
  if (request()->has('price')) {
     $products = Product::withAllTags($tags)->where('price', '<=', request('price'))->get();
  }
  if (request()->has('color')) {
     $products = Product::withAllTags($tags)->whereHas('colors', function ($query) {
          $query->where('name', request('color'));
      })->paginate(20);
  }
  if (request()->has('brand')) {
     $products = Product::withAllTags($tags)->whereHas('brands', function ($query) {
          $query->where('name', request('brand'));
      })->orderBy('created_at', 'desc')->paginate(20);
  }
我尝试添加其他类似的条件

if (request()->has('gender')) {
     $products = Product::withAllTags($tags)->where('gender', request('gender'))->get();
  }
  if (request()->has('price')) {
     $products = Product::withAllTags($tags)->where('price', '<=', request('price'))->get();
  }
  if (request()->has('color')) {
     $products = Product::withAllTags($tags)->whereHas('colors', function ($query) {
          $query->where('name', request('color'));
      })->paginate(20);
  }
  if (request()->has('brand')) {
     $products = Product::withAllTags($tags)->whereHas('brands', function ($query) {
          $query->where('name', request('brand'));
      })->orderBy('created_at', 'desc')->paginate(20);
  }

  else  {
     $products = Product::withAllTags($tags)->orderBy('created_at', 'desc')->paginate(20);
    }  
if(request()->has('gender')){
$products=Product::withAllTags($tags)->where('gender',request('gender'))->get();
}
如果(request()->has('price')){

$products=Product::withAllTags($tags)->where('price'),'

if (request()->has('brand')) {
     $products = Product::withAllTags($tags)->whereHas('brands', function ($query) {
          $query->where('name', request('brand'));
      })->orderBy('created_at', 'desc')->paginate(20);
  }

  else  {
     $products = Product::withAllTags($tags)->orderBy('created_at', 'desc')->paginate(20);
    }  
这使得
else
语句适用于
request()->has('brand')
将所有条件包装在
if
语句中,其余条件包装在
else
语句中

if(request()->has('gender')||request()->has('price')||request()->has('color')||request()->has('brand')){
if (request()->has('gender')) {
     $products = Product::withAllTags($tags)->where('gender', request('gender'))->get();
  }
  if (request()->has('price')) {
     $products = Product::withAllTags($tags)->where('price', '<=', request('price'))->get();
  }
  if (request()->has('color')) {
     $products = Product::withAllTags($tags)->whereHas('colors', function ($query) {
          $query->where('name', request('color'));
      })->paginate(20);
  }
  if (request()->has('brand')) {
     $products = Product::withAllTags($tags)->whereHas('brands', function ($query) {
          $query->where('name', request('brand'));
      })->orderBy('created_at', 'desc')->paginate(20);
  }
}
  else  {
     $products = Product::withAllTags($tags)->orderBy('created_at', 'desc')->paginate(20);
    }  
if(request()->has('gender')| | request()->has('price')| | request()->has('color')| | request()->has('brand')){
if(request()->has('gender')){
$products=Product::withAllTags($tags)->where('gender',request('gender'))->get();
}
如果(request()->has('price')){

$products=Product::withAllTags($tags)->where('price'),'

if (request()->has('brand')) {
     $products = Product::withAllTags($tags)->whereHas('brands', function ($query) {
          $query->where('name', request('brand'));
      })->orderBy('created_at', 'desc')->paginate(20);
  }

  else  {
     $products = Product::withAllTags($tags)->orderBy('created_at', 'desc')->paginate(20);
    }  
这使得
else
语句适用于
request()->has('brand')
将所有条件包装在
if
语句中,其余条件包装在
else
语句中

if(request()->has('gender')||request()->has('price')||request()->has('color')||request()->has('brand')){
if (request()->has('gender')) {
     $products = Product::withAllTags($tags)->where('gender', request('gender'))->get();
  }
  if (request()->has('price')) {
     $products = Product::withAllTags($tags)->where('price', '<=', request('price'))->get();
  }
  if (request()->has('color')) {
     $products = Product::withAllTags($tags)->whereHas('colors', function ($query) {
          $query->where('name', request('color'));
      })->paginate(20);
  }
  if (request()->has('brand')) {
     $products = Product::withAllTags($tags)->whereHas('brands', function ($query) {
          $query->where('name', request('brand'));
      })->orderBy('created_at', 'desc')->paginate(20);
  }
}
  else  {
     $products = Product::withAllTags($tags)->orderBy('created_at', 'desc')->paginate(20);
    }  
if(request()->has('gender')| | request()->has('price')| | request()->has('color')| | request()->has('brand')){
if(request()->has('gender')){
$products=Product::withAllTags($tags)->where('gender',request('gender'))->get();
}
如果(request()->has('price')){

$products=Product::withAllTags($tags)->何处('price',未定义变量在哪一行和哪一页?未定义变量:products(视图:C:\xampp\htdocs\swimwear2\resources\views\category\index.blade.php)在f3407ad99fc10e7e2c6983562937345f02f5bf88.php(第84行)@GauravRai未定义变量:products(视图:C:\xampp\htdocs\swimwear2\resources\views\category\index.blade.php)在f3407ad99fc10e7e2c6983562937345f02f5bf88.php(第84行)中,使用
resources\views\category\index.blaa发布完整的
controller
方法‌​de.php
f3407ad99fc10e7e2c6983937345f02f5bf88.php(第84行)中的未定义变量:产品(视图:C:\xampp\htdocs\swimwear2\resources\views\category\index.blade.php)在f3407ad99fc10e7e2c6983562937345f02f5bf88.php(第84行)中,使用
resources\views\category\index.bla发布完整的
controller
方法‌​de.php