Laravel Left join将where子句添加到右表

时间:2016-05-30 06:36:51

标签: mysql laravel eloquent

如果我在左连接中添加一个where子句,那么这个where子句在右表上工作,我只能得到那些与右表匹配的结果。

$notifications = \DB::table('notifications')
            ->select(\DB::raw("notifications.uuid ,images.local_path as title_image" ))
            ->leftJoin('images','images.owner_uuid', '=' ,'notifications.uuid')
where('images.relation','=','notification_title') ;

如何将此where子句添加到左连接中,这不会产生此问题?

where('images.relation','=','notification_title') ;

1 个答案:

答案 0 :(得分:8)

在左连接中的

必须将所有将在右表上执行的where子句添加到JOIN语句本身。使用此代码

function setImageViewPointHeight() {

  // get current viewport height
  var targetHeight = $(window).height();

  // get current container height
  var containerHeight = $('.container').height();

  // get current container width
  var containerWidth = $('.container').width();


  // only set width if container is higher than viewport
  if (containerHeight > targetHeight) {

    // keep reducing container height/width value by 0.1% until target is reached
    while (containerHeight > targetHeight) {
      containerHeight = containerHeight - (containerHeight * .01);
      containerWidth = containerWidth - (containerWidth * .01);
    }

    // now we have desired calculated width
    $('.container').width(containerWidth + 'px');
  }

}