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

  Рет қаралды 16,849

Laravel Daily

Laravel Daily

Жыл бұрын

This is my opinion on the way of structuring DB profiles for users like "admins" and "users" in separate tables.
Full lesson: "Booking.com API: Profile Fields Structure" laraveldaily.com/lesson/booki...
- - - - -
Support the channel by checking out my products:
- My Laravel courses: laraveldaily.com/courses
- Laravel QuickAdminPanel: quickadminpanel.com
- Livewire Kit Components: livewirekit.com
- - - - -
Other places to follow:
- My weekly Laravel newsletter: us11.campaign-archive.com/hom...
- My personal Twitter: / povilaskorop

Пікірлер: 64
@freelancheer
@freelancheer Жыл бұрын
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.
@reihanboo
@reihanboo Жыл бұрын
well that's why software architecture gets the big bucks😅
@gethermedel3620
@gethermedel3620 Жыл бұрын
this is mostly based on what are the requirements of the system, one thing may be applicable to a project but not on other projects. deciding on how you architect your project depends on that and what are the available resources
@gethermedel3620
@gethermedel3620 Жыл бұрын
this boils down to how much experience the team has on database architecture, frameworks, techniques, infrastructures, coding, and etc. for example, I could teach this and that, but does the team have the experience to pull off this design/architecture?
@younessweb8067
@younessweb8067 Жыл бұрын
Big respect from morocco i have 4 years exp im so proud to watch ur videos
@augustinewafula1346
@augustinewafula1346 Жыл бұрын
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!
@chlouis-girardot
@chlouis-girardot Жыл бұрын
This is so true ! I recently experiment this kind of double auth, it's a terrible idea 🙈
@techiemike9483
@techiemike9483 Жыл бұрын
Your logic makes sense, thank you.
@Sdirimohamedsalah
@Sdirimohamedsalah 2 ай бұрын
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.
@lassestube
@lassestube Жыл бұрын
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.
@mahmoud-bakheet
@mahmoud-bakheet Жыл бұрын
I think you are right and this is a proper way in most cases
@francescoleto2823
@francescoleto2823 Жыл бұрын
In those cases, I used global scopes for each model and interfaces implemented for different data
@quickclean-ninja
@quickclean-ninja Жыл бұрын
Great, Thank you🧑‍💻 🙌🙌💯👍
@lwinmaungmaung
@lwinmaungmaung Жыл бұрын
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
@chibuikeumezinwa7827
@chibuikeumezinwa7827 Жыл бұрын
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.
@mailmerohit5
@mailmerohit5 Жыл бұрын
Nice video sir as always ❤
@free2idol1
@free2idol1 Жыл бұрын
more videos on DB + vanilla php like this please.
@6542fahad
@6542fahad Жыл бұрын
I do agree with you. There should be on table for users and if needed should have separate profile tables.
@IamConstM
@IamConstM Жыл бұрын
yep i did regret having seprate auths for a project that later i needed to add more functions to the different users
@maxtech-84
@maxtech-84 Жыл бұрын
Thanks sir.
@retrowoard
@retrowoard Жыл бұрын
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
@rafli_sugiarto
@rafli_sugiarto 4 ай бұрын
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?
@othmantabati3757
@othmantabati3757 Жыл бұрын
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)
@LaravelDaily
@LaravelDaily Жыл бұрын
I would love to see that "mess with a lot of if statements", maybe some refactoring would make it look better?
@mahmoud-bakheet
@mahmoud-bakheet Жыл бұрын
Somehow I'm in the same situation a lot of if statements
@ernestofavio6735
@ernestofavio6735 Жыл бұрын
Actually, when you use spatie for roles, you need a separate controller and view. The model remains the same. So, you never use even an "if" in your life.
@abdulrahman-ej7me
@abdulrahman-ej7me Жыл бұрын
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
@mfonabasiudobiambrain7134
@mfonabasiudobiambrain7134 Жыл бұрын
It doesn't work in a scenario where a customer can signup in multiple stores as a different user using the same email and phone number. Where the user types are: Admins Store owner Customers Because a table will be forced to have duplicate emails and phone numbers with store_id as the composite key to uniquely identify a user for a specific store. I believe in this scanerio you will need a new table for customers.
@Kodunmi
@Kodunmi 6 ай бұрын
Basically in a fin tech system or system that handles money, please make sure you seperatate concerns as much as possible, do not mix match users and admins, when one is bridged, you're finished.
@darknet106
@darknet106 Жыл бұрын
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
@LaravelDaily
@LaravelDaily Жыл бұрын
I just started learning Laravel and just never needed to switch to anything ever :)
@yungifez
@yungifez Жыл бұрын
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
@TristanBailey
@TristanBailey Жыл бұрын
When ever I’ve done this before it’s made so much sense. Then the code goes to crap as two different entities make more complex not more secure
@GabrielOliveira-hm6gi
@GabrielOliveira-hm6gi Жыл бұрын
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.
@LaravelDaily
@LaravelDaily Жыл бұрын
Ok to repeat, in most cases
@akinoreh
@akinoreh Жыл бұрын
User types and roles are different things. So having "admins" and "users" tables is impractical. There should be a single users table. Then you can differenciate users (types) by using sub-tables (see Class Table Inheritance). Roles/permissions, on the other hand, is a seperate issue and should have its own tables.
@mhknhinvy
@mhknhinvy Жыл бұрын
Hi can u make a Complete video on laravel spatie roles and permissions?? Please , It will be so helpful!!
@LaravelDaily
@LaravelDaily Жыл бұрын
I have a lot of content about that package on LaravelDaily: laraveldaily.com/tag/spatie-laravel-permission Or generally about permissions: laraveldaily.com/tag/auth-roles-permissions
@mhknhinvy
@mhknhinvy Жыл бұрын
@@LaravelDaily Thanks a lot!❤
@Mr.Error__
@Mr.Error__ Жыл бұрын
What is the best practice : table for user and admin or merge users and admins in same table?
@LaravelDaily
@LaravelDaily Жыл бұрын
Have you watched the video?
@MohamedSalah-fg1np
@MohamedSalah-fg1np Жыл бұрын
هو لسه موضح في الفيديو انه متفصلش بينهم .
@amanitimoth7294
@amanitimoth7294 Жыл бұрын
What is the name of tool you used design the tables shown.
@freelancheer
@freelancheer Жыл бұрын
I think its MySql Workbench.
@LaravelDaily
@LaravelDaily Жыл бұрын
Dbeaver
@amanitimoth7294
@amanitimoth7294 Жыл бұрын
@@LaravelDaily thanks for your response
@goncalves_luis
@goncalves_luis Жыл бұрын
Email issue: Lets use your Patient/Doctor example, but it can be User/Admin, whatever. I'm assuming that the email is defined as unique, so, lets get to the issue: A patient can in practice be a doctor too, because doctors can get sick also. In this situation then a person can register as a patient and as doctor, but unfortunately they cant use the same email, though it would be pratical that they should be able to. I imagine you can circumvent this by not specifying as unique and they put some registration logic to check email and role to permit email duplication but restrict it if the user has the same role. What would be your approach to work-around this? Table wise, logic, etc, how would be your best solution for this?
@LaravelDaily
@LaravelDaily Жыл бұрын
If possible, at all times I would avoid the situation of same person with same email in different roles. Need different roles? Use different emails. In rare cases, you can't avoid it, then role_user pivot table. Everything else is hard to explain in a short comment, need a separate video.
@nero3700
@nero3700 Жыл бұрын
There probably are other examples, but in your example the same person as a doctor would use his work email, while he'd use his personal email as a patient.
@goncalves_luis
@goncalves_luis Жыл бұрын
@@nero3700 Yes, in that example, the doctor would most likely use a working email and a personal email. But, that is not what i was trying to point out. But, there is always a possibiltiy that the doctor would use the same email for both cases, either the personal or working email.
@goncalves_luis
@goncalves_luis Жыл бұрын
@@LaravelDaily Ok, it is always a solution.
@freelancheer
@freelancheer Жыл бұрын
Its not a good practice to allow the same email used twice: see why at big tech companies. The email is in theory your ID of that site.
@intipontt7490
@intipontt7490 Жыл бұрын
Separate Databases should be concerned with different things. In Laravel, Eloquent relationships do not work well across different connections (database configurations). If you want to separate concerns in different databases, user profiles are not the way to go. I personally don't do it because my projects are not big enough to require it but assuming the database driver is used for some of the configs, things that can be moved to a separate database are the job tables (failed_jobs, jobs), the session table (sessions) and the cache table (assuming you use the database driver for cache instead of something like redis). I think it's overkill anyways.
@tikadahal7597
@tikadahal7597 Жыл бұрын
Really cant say which one is better. If using guards makes things better why not use them??? I had similar situation where i created online vacancy portal. I maintained that with guards admin for admins and default web guards for user. Roles and permissions were maintained only for admins as admins had two roles maker and checker. Was that a bad approach then????
@brucealamin175
@brucealamin175 Жыл бұрын
I didn’t know that you are answering questions on twitter.. probably cause i dont use twitter.. you mind if i share some code with you for your review? Am trying to become a better laravel developer and your help would be highly appreciated.
@LaravelDaily
@LaravelDaily Жыл бұрын
I sometimes do that if I see a case usefu not only for that person but for many people in my audience. If you feel your case is like this and you're ok with waiti foe a month for review, email me povilas@laraveldaily.com
@legato0
@legato0 Жыл бұрын
I prefer separate admin and user logins. The administrator cannot have the option of reminding/resetting the password and you can additionally protect against unwanted number of incorrect logins to the system or restrict access only from a specific IP.
@Novica89
@Novica89 Жыл бұрын
You can do that while having admins in the users table.
@genechristiansomoza4931
@genechristiansomoza4931 Жыл бұрын
It is doable even if there is one user table. Looks like a permission issue
@insaneskullgaming
@insaneskullgaming Жыл бұрын
Video title is kind of Misleading, Roles are not considers as Users. What here talked about is User Type and it's separate profiles. I consider role as group of permissions, One user can have n number of roles as per requirement. Depends on size of application may be one or multiple roles for user.
@Shiv-vb1re
@Shiv-vb1re Жыл бұрын
How can you do this? that’s treason
9 Tips for Shorter Laravel Code
10:16
Laravel Daily
Рет қаралды 61 М.
Refactor "Senior" PHP Code with Early Returns
12:09
Laravel Daily
Рет қаралды 26 М.
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 159 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 24 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 13 МЛН
ОСКАР ИСПОРТИЛ ДЖОНИ ЖИЗНЬ 😢 @lenta_com
01:01
User Roles: Many Fields in Users, or Separate Tables?
5:26
Laravel Daily
Рет қаралды 13 М.
Laravel Translations: Store in PHP or JSON Files?
7:34
Laravel Daily
Рет қаралды 19 М.
Laravel Pivot Tables: Simple to Advanced Many-to-Many
12:24
Laravel Daily
Рет қаралды 118 М.
Laravel: Avoid Try-Catch In Every Method (What To Do Instead)
4:45
Laravel Daily
Рет қаралды 29 М.
18 Laravel/PHP Tips in 10 Minutes: June 2024
10:41
Laravel Daily
Рет қаралды 7 М.
Laravel + Livewire todo app (and so much more)
16:41
Aaron Francis
Рет қаралды 34 М.
Learnings from our multi-tenant Laravel application
9:58
Sabatino Talks Dev
Рет қаралды 12 М.
Laravel SPA Authentication - setup and common mistakes
16:55
Chúa ơi - Hãy thử cái này #automobile #funny #shorts
0:12
hoang quach
Рет қаралды 28 МЛН
УДИВИЛА МЛАДШУЮ СЕСТРУ
0:50
Li ALINA
Рет қаралды 4,1 МЛН