I have many-to-many relationship between users and user roles, i want to check if an user has the given role like
if ($user->belongs($role->id)) doSomething();
but i can't find it in the docs.
Is there such a shortcut to check if a given model has a relationship, or a native L4 method?
This should work for you mate
//get the attached roles of someuser
$someusers_roles = $someuser->related()->lists('role_id');
//check if he has a particular role attached
if(in_array($particular_role->id, $someusers_roles))
{
doSomething();
}
hope this helps you out.