I think the SQL would look like this:
SELECT DISTINCT role_user.user_id as user_id, permission_role.permission_id as permission_id
FROM permissions
INNER JOIN permission_role on permission_role.permission_id = permissions.id
INNER JOIN role_user on role_user.role_id = permission_role.role_id
WHERE role_user.user_id = 5
meaning the view would be:
CREATE VIEW phantom_user_permission AS
SELECT DISTINCT role_user.user_id as user_id, permission_role.permission_id as permission_id
FROM permissions
INNER JOIN permission_role on permission_role.permission_id = permissions.id
INNER JOIN role_user on role_user.role_id = permission_role.role_id
and the model would look like:
public function permissions() {
return $this->belongsToMany(Permission::class, 'phantom_user_permission');
}
Is this silly? Is there a performance hit rather than using the previously described method?
The only issue I can see is the possibility of someone using ->sync()
on it, and things blowing up horrendously!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community