Laravel在哪里被忽略

问题描述

我的laravel“ where”似乎被忽略了。 -> where('products.hide_product','=','N') 关于我在做什么错的任何想法吗?

  $products = Product::join('brands','products.brand_id','=','brands.brand_id')
                            ->join('categories','products.cat_id','categories.cat_id')
                            ->leftJoin('images','products.product_id','images.product_id')->where('img_priority','1')->orWhere('img_priority',null)
                            ->where('products.hide_product','N')->where('products.group_id',$groupID)->orderBy('img_priority','DESC')
                            ->get(array('products.en_71','products.astm','images.file_name','products.product_name','products.collect_part_no','brands.brand_name','categories.cat_name','products.status','images.file_type','products.pop','products.color_label','products.ai_complete'));
            

解决方法

您可以使用第一个where那里的连接来移动连接:

$products = Product::join('brands','products.brand_id','=','brands.brand_id')
    ->join('categories','products.cat_id','categories.cat_id')
    ->leftJoin('images',function ($join) {
        $join->on('products.product_id','images.product_id')
        ->where('img_priority','1')
        ->orWhere('img_priority',null);
    })
    ->where(
        ['products.hide_product','N'],['products.group_id',$groupID],)
     ->select('products.en_71','products.astm','images.file_name','products.product_id','products.product_name','products.collect_part_no','brands.brand_name','categories.cat_name','products.status','images.file_type','images.img_priority','products.pop','products.color_label','products.ai_complete')
    ->orderBy('img_priority','DESC')
    ->get();
,

请尝试以下代码。

$products = Product::join('brands',function($join)) {
        $join->on('products.product_id','images.product_id')
             ->where(function($query){
                $query->where('img_priority','1')
                      ->orWhere('img_priority',null)
            })
        }
        ->where(function($query) {
            $query->where('products.hide_product','N')
                  ->where('products.group_id',$groupID)
        })
        ->orderBy('img_priority','DESC')
        ->get(array('products.en_71','products.ai_complete')
             );

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...