Home > front end >  Relation still returning row even if data not exist in laravel
Relation still returning row even if data not exist in laravel

Time:09-18

I have this query :

 $data=Booking::whereHas('service.user', function($query) use ($id){
                    $query->where('user_id', $id);
 })->get();

Here service.user relate to user, i want to return only those record from booking table where user_id exist in service.user relation but using this relation i'm still getting record from booking table when the user_id is not present in service.user relation. Can anybody suggest some solution. Thanks

CodePudding user response:

Can you try this? I suppose I could be wrong but why not give it a try (-:

$data = Booking::whereHas('service', function ($query) use ($id) {
            $query->whereHas('user', function ($query) use ($id) {
                $query->where('user_id', $id);
            });
        })->get();
  • Related