Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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 如何在laravel5的join子句中使用原始查询?_Php_Laravel 5 - Fatal编程技术网

Php 如何在laravel5的join子句中使用原始查询?

Php 如何在laravel5的join子句中使用原始查询?,php,laravel-5,Php,Laravel 5,我在laravel5的join子句中使用了多个条件,其中有一个条件作为原始条件传递。怎么通过呢 我得到了这个错误 调用未定义的方法Illumb\Database\Query\JoinClause::whereRaw() 代码是 ->leftjoin('log_simple_calory as LC', function($join)use($tz_lccreated_date,$dateRange){ $join->on('LC.user_id_fk','=','UA.user_

我在laravel5的join子句中使用了多个条件,其中有一个条件作为原始条件传递。怎么通过呢

我得到了这个错误 调用未定义的方法Illumb\Database\Query\JoinClause::whereRaw()

代码是

->leftjoin('log_simple_calory as LC',
function($join)use($tz_lccreated_date,$dateRange){
  $join->on('LC.user_id_fk','=','UA.user_id_fk');
  $join->on('LC.is_active','=',DB::raw('1'))
  ->whereRaw('date('.$tz_lccreated_date.')'. $dateRange);
})

whereRaw
应该在
JoinClause
之外:

->leftjoin('log_simple_calory as LC',
function($join)use($tz_lccreated_date,$dateRange){
  $join->on('LC.user_id_fk','=','UA.user_id_fk');
  $join->on('LC.is_active','=',DB::raw('1'))
})->whereRaw('date('.$tz_lccreated_date.')'. $dateRange);

如果您使用的是laravel 5及以上版本,此网站非常有用, 用于编写原始查询和内容


我猜它可能只是
->其中(DB::raw(…)
-no?@ArturKäpp,它不起作用。在我的场景中,它不应该在外面。这取决于你的需要。所以,如果您想使用insidejoin子句,那么它将不会被执行并返回一个错误。在这种情况下,我们可以使用子查询。SQL查询中的
where
子句总是在连接之后。问题是,
where
限制了集合中的条目,因此它肯定在外部,因为闭包中没有集合。where子句位于联接之后并不是一种改进,它取决于联接条件,当我们将外键映射到表时,我们可以在join子句中使用多个where条件。您指的是
on
子句,而不是
where
子句。