Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raffelustig's avatar

Check if user is admin

We have two separate types of admins. One "superadmin" that can do a lot. Then we have a "lower" admin that can do other things. In the code we have for the logged in user as "superadmin" this:

@if(\Auth::user()->is_admin) and the column in the users is_admin is 1. This works of course.

But for the "lower" admin there is a value in another table, not in the users table. It is in "clubs_admins" and when the user is that admin there is value "admin" in the column "role". How should I formulate the @if - statement for for that? Tried several ways but no success.

The table contains of: id, users_id, clubs_id, role,created_at,updated_at and deleted_at.

0 likes
4 replies
asadbekDev's avatar

bro create a roles table and role_user and users roles table include your roles SuperAdmin, Admin , Manager .. like this

raffelustig's avatar

Yes, I was thinking of include an extra column in users table for "loweradmin". Like @if(\Auth::user()->is_Lowadmin) should work.

martinbean's avatar

@raffelustig Or you could take @asadbek2000’s advice and create a column called role in your users table, and then that column can have a value like “admin”, “superadmin” etc instead of checking random integer values.

if ($user->role === 'admin') {
    // User can do some things
} else if ($user->role === 'super_admin') {
    // User can do ALL the things!
}
raffelustig's avatar
raffelustig
OP
Best Answer
Level 2

I'll end this and work on another angle. Thanks.

Please or to participate in this conversation.