Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Role without Name #12

Open
ghost opened this issue Jun 4, 2015 · 3 comments
Open

Check Role without Name #12

ghost opened this issue Jun 4, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 4, 2015

Hello @gravitano,

can I check with your plugin, if the user has an role without knowing the name ?

Background:

Only user with a role can login in the admin panel. So I have a custom middleware, in which I will check, If the user is auth and if the user has an role (but I don't know the name).

Currently I use database access via model.

Is there a better solution ?

Greetings!

@gravitano
Copy link
Member

But, you know the role Id ? Try this.

$user = Auth::user();

$roleId = 1;

$hasRole = $user->roles()->whereId($roleId)->first();

dd($hasRole);

Maybe I would add search by id to is method.

@ghost
Copy link
Author

ghost commented Jun 4, 2015

Hey @gravitano,

I don't know anything.

My idea via model is, that I search, if an entry exists within "role_user" table.

Yes: Role attached
No: No Role attched, error message and redirect.

Greetings

@astroanu
Copy link

astroanu commented Jan 7, 2016

hey @heikobihlmaier you're question makes no sense. How can you check a role without knowing what it is? if you know a permission you can check that on the user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants