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

  Рет қаралды 18,197

Laravel Daily

Laravel Daily

Күн бұрын

Пікірлер: 65
@younessweb8067
@younessweb8067 Жыл бұрын
Big respect from morocco i have 4 years exp im so proud to watch ur videos
@chlouis-girardot
@chlouis-girardot Жыл бұрын
This is so true ! I recently experiment this kind of double auth, it's a terrible idea 🙈
@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?
@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
@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!
@rafli_sugiarto
@rafli_sugiarto 9 ай бұрын
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?
@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.
@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.
@6542fahad
@6542fahad Жыл бұрын
I do agree with you. There should be on table for users and if needed should have separate profile tables.
@Sdirimohamedsalah
@Sdirimohamedsalah 7 ай бұрын
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.
@francescoleto2823
@francescoleto2823 Жыл бұрын
In those cases, I used global scopes for each model and interfaces implemented for different data
@mehdiabderrahmaneyahiaoui4700
@mehdiabderrahmaneyahiaoui4700 21 күн бұрын
Thanks for the explanation! What if the user can have multiple roles ( for instance: doctor and patient)?
@techiemike9483
@techiemike9483 Жыл бұрын
Your logic makes sense, thank you.
@IamConstM
@IamConstM Жыл бұрын
yep i did regret having seprate auths for a project that later i needed to add more functions to the different users
@mahmoud-bakheet
@mahmoud-bakheet Жыл бұрын
I think you are right and this is a proper way in most cases
@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
@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 11 ай бұрын
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.
@free2idol1
@free2idol1 Жыл бұрын
more videos on DB + vanilla php like this please.
@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.
@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
@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
@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
@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.
@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
@quickclean-ninja
@quickclean-ninja Жыл бұрын
Great, Thank you🧑‍💻 🙌🙌💯👍
@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.
@mailmerohit5
@mailmerohit5 Жыл бұрын
Nice video sir as always ❤
@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 :)
@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
@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
@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????
@maxtech-84
@maxtech-84 Жыл бұрын
Thanks sir.
@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!❤
@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.
@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
@Shiv-vb1re
@Shiv-vb1re Жыл бұрын
How can you do this? that’s treason
Laravel Roles and Permissions: All CORE Things You Need To Know
16:32
Laravel Daily
Рет қаралды 225 М.
User Roles: Many Fields in Users, or Separate Tables?
5:26
Laravel Daily
Рет қаралды 13 М.
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 3,5 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 101 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 45 МЛН
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 10 МЛН
Most Devs are Hired NOT to Create New Software
5:20
Laravel Daily
Рет қаралды 985
Static Methods in Laravel/PHP: When and How?
10:39
Laravel Daily
Рет қаралды 18 М.
Vercel V0: Clone Any Website Instantly with Just a URL
5:55
Hustling Labs
Рет қаралды 1,5 М.
Learnings from our multi-tenant Laravel application
9:58
Sabatino Develops
Рет қаралды 17 М.
Jetstream/Fortify Multi-Auth: Roles, Permissions and Guards
19:00
Laravel Daily
Рет қаралды 100 М.
8 Career Tips from My 25 Years as Developer
12:08
Laravel Daily
Рет қаралды 7 М.
Laravel Eloquent: Deeper Relationships with One Query
10:37
Laravel Daily
Рет қаралды 144 М.
Laravel: Separate Admin/User Areas - Designs, Routes, Permissions
6:39
Why aren't you using Fastify? Or Koa? Or NestJS?
9:58
Maximilian Schwarzmüller
Рет қаралды 66 М.
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 3,5 МЛН