I have 6 tables:
permissions:
id
permission_name
roles:
id
role_name
user_roles:
id 
user_id 
role_id
user_permissions:
id 
user_id 
permission_id
role_permissions:
id
role_id
permission_id
users:
id
username
email
Now I like to add a custom function into my Eloquent model for permissions named getUsersWithPermission().
Now it is possible that user has the permission by the role he has given (user table join on user_roles, join that table on role_permissions and last that table join on permissions.
Or the user has a specific permission set in the user_permissions table (join user_permissions table on user table and join the permissions table on the user_permissions table)
How can I create a Eloquent model function that returns all the users with a specific permission say: "notification.error.process" where that is the permission name
A hasMany doesn't quite do what I want (and I cannot define multi tables in there). I am using Laravel 5.6.
