id name username email password
id name
role_id -> primary of role user_id -> primary of user module_id menu_id permission
Select role_detail., role.name, user. from user join role_detail on role_detail.user_id = user.id join role on role.id = role_detail.role_id
how can i define above query in eloquent in user model
If you have followed laravel documentation and have defined belongsToMany relations you could do simply:
$users = User::with("roles")->all();
So i don't think it's really necessary to wrap it in a method in the user model.
For completeness:
foreach($users as $user){
foreach($user->roles as $role){
//here you have access to all user fields and related roles fields
}
}
Thanks this one worked for me .... :-)
can you help me for this complex query on the below given link
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community