简体   繁体   English

如何在何时仅获得 laravel eloquent 中的活动关系

[英]how to get only active relationships in laravel eloquent in when

hi i have a when eloquent clause that i want to pick only the properties that has active relation of discount so my code is like below:嗨,我有一个 when eloquent 子句,我只想选择具有折扣活动关系的属性,所以我的代码如下所示:

->when($has_discount, function ($query, $has_discount) {
            $query->with([
                'accommodationRoomsLimited' => function ($q) use ($has_discount) {
                    $q->has('discount');
                }
            ]);

i will go for my hotels and then inside that i pick rooms and i want to pick hotels with active relation of discount on room but this code right now is doing nothing for me how can i achive that??我将 go 用于我的酒店,然后在里面我选择房间,我想选择与房间折扣有积极关系的酒店,但是这个代码现在对我没有任何作用,我怎么能做到这一点?

the closer function in which set condition like that更接近 function 在这样的设置条件下

$query->with([
            'accommodationRoomsLimited' => function ($q) use ($has_discount) {
                $q->where('discount', 'active');
            }
        ]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM