Skip to content
Advertisement

Userpermission pivot-function is only accessible via the Auth class

I have a simple Userpermission System consisting of 3 tables: users, permissions and the pivot table permission_user.

This is the User model:

JavaScript

and here is the Permission Model:

JavaScript

Now when I try to get all the permissions of the currently logged in user with this:

JavaScript

it works without problems.

But when I try to get another Users Permissions like this:

JavaScript

I get the following error:

JavaScript

How do I proceed?

Advertisement

Answer

I think you’re missing first() here, since you can’t get relations of a query builder object. Try this :

JavaScript

This first() will actually return User object, and then you can load its relations.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement