Laravel: Separate DB Tables for Roles? I Don't Recommend It

preview_player
Показать описание
This is my opinion on the way of structuring DB profiles for users like "admins" and "users" in separate tables.

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

Great video! This is a skill that I can use for many projects. I’m grateful for your guidance and expertise. Thanks for sharing your knowledge!

augustinewafula
Автор

Big respect from morocco i have 4 years exp im so proud to watch ur videos

younessweb
Автор

This is so true ! I recently experiment this kind of double auth, it's a terrible idea 🙈

chlouis-girardot
Автор

Caleb porzio made the parental package which is great and could be combined with this approach where each model could have a separate profile linked.

lassestube
Автор

I think this is the hard part of any project: to separe concerns. It would be great for many of us to teach us how to proper start a project arhitecture rather than keep teaching us how to code in Laravel. The coding is much easier if a developer has a good start.

freelancheer
Автор

I am creating a project where the User can have one of three roles: Admin, Teacher, or Student.

To achieve this, I created a "users" table for authentication purposes and fields that are commonly owned by "users", such as "name", "profile_picture", and "phone_number".

Additionally, I created a separate table for each role (admins, teachers, and students), each with its own specific fields. For example, the teachers table has a "subject" field, and the students table has a "class_group_id" field (foreign key). Does this match the setup described in the video?

rafli_sugiarto
Автор

In those cases, I used global scopes for each model and interfaces implemented for different data

francescoleto
Автор

I see no issues with separate guards and using polymorphism for logic sharing. I see more issues with using single guard for two different kind of users which can at times cause vulnerability and require lot's of logic to separate concerns.

There's no better way until the project at hand demands you pick one approach instead of the other.

chibuikeumezinwa
Автор

Si extiendo mis tablas como profesores y estudiantes con la de usuarios y esta tabla de usuarios tiene una relación con roles, que puedo hacer para que solo ciertos roles accedan al sistema, por ejemplo: que solos los usuarios de la tabla profesores (que tendrá rol de profesor en la de usuarios) y los usuarios con rol de admin puedan acceder al sistema, y los usuarios de la tabla de estudiantes no puedan acceder al sistema web pero si a la autenticación por API

retrowoard
Автор

User role or user type can be helpful, depending on user role or user type. This allows user to choose between login as doctor or as user or switching if they need it from the same ui.

Sdirimohamedsalah
Автор

It is normally indifferent but huge different in database with huge amount of users and also normalization.

Index sizes, first row admin vulnerabilities, etc in my opinion

lwinmaungmaung
Автор

yep i did regret having seprate auths for a project that later i needed to add more functions to the different users

IamConstM
Автор

more videos on DB + vanilla php like this please.

freeidol
Автор

I think you are right and this is a proper way in most cases

mahmoud-bakheet
Автор

I do agree with you. There should be on table for users and if needed should have separate profile tables.

fahad
Автор

i see it as an area if some users type allowed to enter this area but some of them has limitation inside it. it`s ok to be one table one auth but if it`s a different area not all user allowed to enter it like dashboard it just allowed for admins to enter this area i see it`s better to be a separate table with separate guard and auth

abdulrahman-ejme
Автор

The app I'm currently working on, I don't have an option


I have to use seperate guards ( although, I'm usung the same user table different guard names )

I have role categories, not roles. My boss wants vendors to have the ability to create roles eg accountant, users etc

Then the system_users can create roles in their own end

There's no logical way to do this with the available roles package and im not ready to recreate my own

So I'm using multi authentication guards and extended spatie permissions to allow system users be true global roles and then vendor roles are normal roles


Have i encountered issues, yes. Am i encountering issues, yes

But that's my only option

yungifez
Автор

Hello, your lessons are very good! Thanks you!
I have a question about not this video.

Why you choose laravel instead of symfony? If you record video about that, it will be awesome

darknet
Автор

just recently i made 2 school managment projects
i used spatie permissions in the first project to separate between (admins, teachers, students and parents) and honestly i regret that, the project was a mess and i had to write a lot of if statements
and now i'm working on the second project and i'm using guards to separate them and it is looking good (i didnt finish yet but for now i like what i see)

othmantabati
Автор

If both the patient and doctor have an address, is it okay to repeat all the address fields in both tables or create a new polymorphic address table? In this sceneario an admin doesn't need an address but it's required for a patient and doctor.

GabrielOliveira-hmgi