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