dongqingcheng2903
2017-10-14 05:13
浏览 628
已采纳

Laravel Eloquent在WhereHas中无效

I'm trying to display all business locations hours for the current day and if the location does not have hours listed in the database, I'm wanting to show it but as null.

Example:

Business 1: 10:00 am - 5:00 pm
Business 2: 10:00 am - 9:00 pm
Business 3: Closed (null)
Business 4: 10:00 am - 5:00 pm

The issue i'm having is in the controller. It's not showing the nulls with the whereHas clause.

$Locations = Locations::with('StoreHours', 'Managers', 'ShiftLeads')
                ->doesntHave('StoreHours')->orWhereHas('StoreHours', function ($query) {
                    $query->where('opening_time','>=', date('Y-m-d') . ' 00:00:00');
                    $query->where('opening_time','<=', date('Y-m-d') . ' 23:59:59');
                })
            ->get();

The only data that is showing is if any store has never had store hours. How can I show all stores and get null if there is no hours?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试显示当天的所有营业地点营业时间以及地点是否列出了营业时间 数据库,我想显示它但是为空。</ p>

示例:</ p>

 商业1:10:00 am  -  5  :00 pm 
Business 2:10:00 am  -  9:00 pm 
Business 3:Closed(null)
Business 4:10:00 am  -  5:00 pm 
 </ code> </ pre> 
 \  n 

我遇到的问题是在控制器中。 它没有使用 whereHas </ code>子句显示空值。 </ p>

  $ Locations = Locations :: with('StoreHours','Managers','ShiftLeads')
  - &gt; doesntHave('StoreHours') - &gt; orWhereHas(  'StoreHours',函数($ query){
 $ query-&gt; where('opening_time','&gt; =',date('Ym-d')。'00:00:00'); 
 $  query-&gt; where('opening_time','&lt; =',date('Ym-d')。'23:59:59'); 
})
  - &gt; get(); 
 <  / code> </ pre> 
 
 

显示的唯一数据是任何商店从未有过商店营业时间。 如果没有小时,我如何显示所有商店并获得空?</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题