Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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!

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Towerful towerful Joined 4 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.