Hi , I create student ,teacher ,admin ,parent and is a part of user class I make name,email,authentication is common for all of these previous class ,
My question is : when I try to create new student for example I make the following
1- make a big validation for both user parameter and student parameter in student class
2- if it's valid I create new user and save it at student class
3- if it's save ok I create a new student
is this design pattern is ok and if is there other better design kindly help
many thanks dear, but the problem is each user student ,admin,teacher ,.. has different properties so for that I create the common attributes in user class and other unique attributes in it's specific class
@alrazyreturn , what do you mean have different user properties,?
remember there should be a profiles table to store users properties,
meanwhile you can use nullable in users or profiles table scheme on properties that are optional, that's if you decide to use one single profiles table for their properties.
but if you have use student, admin...etc as representing their different profile, then what's your challenge ?
I suppose you could structure your data model like @ayekoto says but also create an interface to interact with your desired users
Quick n' Dirty way would be to create ie. a Student model and point it's $table variable towards your users table. Then add a filter somewhere to ensure that you can't put a User with the Teacher role in it.
This would allow you to use a Student model to interact with your User model where their role is a student
many thanks for your replies ,but how I can make different validate with other optional fields , I mean I need to check level is inserted in student and I want job in teacher how I can validate in different cases ,sorry If my question is silly
@ayekoto Well it's pretty dirty, and you don't really need a Model to represent a User's role, it's probably better to create a class which looks for a user Model of a given role
It would mostly be for sematic reasons, like when you update your User you can't see if you are talking about a Student or a Teacher, but if you had classes which represented users based on their roles, you could quickly differentiate them :)