0

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($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 ??

Salman Zafar
  • 3,844
  • 5
  • 20
  • 43
Farshad
  • 1,830
  • 6
  • 38
  • 70

1 Answers1

1

the closer function in which set condition like that

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