Using Laravel eloquent how do I make a query like this:
select * from branches where user_id =(select id from users where name ='sara' )
Using Laravel eloquent how do I make a query like this:
select * from branches where user_id =(select id from users where name ='sara' )
I would split it into two queries. First getting the id, then getting the list. Expecting your models to be called "User" and "Branches"
$user = User::where('name', 'sara');
$id = $user->id;
$branches = Branch::where('id', $id);
This site may help you Link
Assuming that you have a
user
relationship in yourBranch
model you could use whereHas:Update
If you're using v8.57.0 or above, you can now use the whereRelation() method instead: