PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] Relation still returning row even if data not exist in laravel

 February 10, 2022     eloquent, laravel, laravel-5     No comments   

Issue

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


Solution

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();


Answered By - Huy Phạm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing