Admin ,Users ---> separate table VS single table

Published 2 months ago by mac03733

hi guys. i am new to laravel and i know this is probably a matter of preference.

but i am curious which approach is the best

tykus
tykus
2 months ago (690,170 XP)

Single table for me unless there is a compelling reason not to.

Cronix
Cronix
2 months ago (785,240 XP)

users, roles. Or users, with is_admin flag. A user is a user.

procell

Also users, roles. Even if there's a single role, it's easier to extend in the future with separate tables, I find.

mac03733

are there any major drawback i should worry bout with any of them .. and which questions or likely situations would require one or the other approach

florianhusquinet

If you decide to build an extra table for the admins you then have to extend the default auth system which is a lot of extra work considering you could simply have a role and do $user->hasRole('admin') when needed.

Another option if you do not want to use roles nor a flag and need extra columns for your admins is to use a one to one relationship. Your admins table can have the user_id as well as the columns you need without messing with Laravel's auth system.

Please sign in or create an account to participate in this conversation.