How can I write query for below table in Laravel.
Like In my app logged user id is 109
So I need whose user match with logged user in BlindDate and PaidDate table to user id.
I want need expected output is :
data[
'blind_users':[
{
'uuid':'rvfv',
'user_id':109,
'touser':[
{
'name':'james',
'email':'[email protected]'
}
]
},
{
'uuid':'rvfv',
'user_id':109,
'touser':[
{
'name':'james',
'email':'[email protected]'
}
]
},
],
'paid_date_users':[
{
'uuid':'rvfv',
'user_id':109,
'touser':[
{
'name':'james',
'email':'[email protected]'
}
]
},
]
]
2
Answers
Hopefully you have setup the eloquent Model and its relations since you are using Laravel for this project!
If you only have the user id you can query the User model like so
If you have an authenticated user you can just return the user without any eager loading or just call it in you blade like
auth()->user()
Ans: Use these two function in user model.
Query:
If you have a multiple user, user
hasMany
relation.Please use this code, I think your code working.