Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lola's avatar
Level 1

Laravel roles

Hello , I need some advice ...

I have two types of users, members and their secretaries (all columns are different except email, password fields) , also secreteraies don't access some pages...

The login form is the same , so I add some table (users) with types => member, secretary , for each type I have some profile table , also for secretaries table I have some role_id for choosing permissions .

Is it good idea or no?

May be I need to have two different tables? members & secretaries? (the same form little confusing)

0 likes
2 replies
xmarks's avatar

If the data is really all different, you could do the following:

  • users table: id | role | first_name | last_name | email | password | ... other default fields of Laravel Auth
  • data_members table: id | user_id | ... Other data for Members
  • data_secretaries table: id | user_id | ... Other data for Secretaries

Relations would be:

  • User Model:
public function dataMember() {return $this->belongsTo(DataMember::class);}
public function dataSecretary() {return $this->belongsTo(DataSecretary::class);}
  • DataMember Model:
public function user() {return $this->hasOne(User::class);}
  • DataSecretary Model:
public function user() {return $this->hasOne(User::class);}

to get the data:

if($user->role === 'member') :
    $user->load('dataMember');
else: 
    $user->load('dataSecretary');
endif;

Edit

Just to be clear, Login Form would remain the same.

I would advise creating a MiddleWare, which would differentiate Users based on their roles. So they would see different pages like, Profile Page, Change your Settings, and so on...

Lola's avatar
Level 1

yeh I have something like that, just in dataSecretary (secretary_profiles) I have role_id, and i have roles table and role_permission table, I use gates

if (! Gate::allows('event_create')) { return abort(401); }

@can('event_create')

/** some view ***/

@endcan

members can see all pages, but secretaries just a part. I don't know all details, but for example for him will be visible only some part of page... so if I will use MiddleWare can I have access only some part of page?

p.s. I use MiddleWares for admin panel access... (guards:admin, api)

Please or to participate in this conversation.