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

AbdulBazith's avatar

Suggestion for Multiple Authentication package in laravel.

Guys Iam working with a project School Management System

i have completed Student,Staff, student-attendance, staff-attendance, class,section modules.

now i have to work with Authentication module.

I have googled about multiple authentication, many of them suggested spatie package.

here is what my user table looks

id  year_id     user_name   user_type   admin_no    user_phno   password
1      1        AAA          student      STU01     123         --
2      1        BBB          student      STU02     236         --
3      1        CCC          staff        STAF01    127         --
4      1        DDD          staff        STAF02    987         --

Almost more than 1000 students and 100 staff details are entered in the application. the application is in live.

Now i need to proceed with multiple authentication, so do i need to restrucutre the user table? is there may be any data loss??

How my authentication must be is,

All staff comes under the role STAFF they has permission to access only the student attendance, student mark module,

Few nonteaching staffs are there they come under COORDINATOR role. they can access only1 module in theapplication

Accountant and Sub-accountant fall under ACCOUNTANT role and they has permission to access Fee payment module, fe strucutre module.

the Roles are dynamic that the principal can create N number of roles and can add the user in any one role.

Parent also can access the application, they can only view theier student, details, attendance, fee payment, just only can view it,

i have another doubt also, eacher staff will be class teacher of 1 class (say for example staff CCC will be class teacher of V std), so that only that staff (CCC) has the permission to put attendance and add mark details of that class(V std) students, all other staff can just view that, but they dont have permission to edit or delete it,

so i think i need to map(tag) staff with respective classes am i right??

already i have a class and section table like below

id  year_id     class_name
1   1           V std
2   1           VI std

Section table

id  year_id     class_id        section_name
1   1           1                   A
2   1           1                   B

So after my reference i understood that, i need role table, permission table, role-permission table, module- permission table,role-module table.

is my understanding is correct? or else am i moving in wrong way? is these tables are necessary?? else i need more tables?

Kindly suggest any package and also video links for my multiple authentication.

else i can do this authentication manually. in my last project how i worked with athentication is,

my loginfunction

public function login(Request $request)
 {
  if (auth()->attempt(request(['user_name', 'password'])) == true  && Auth::user()->hotel_id == $request->hotel_id)

  {

   return redirect()->route('RegisterLogin.index');

  }
  else {
   return back()->withErrors([
    'message' => 'The email or password is incorrect, please try again',
   ]);

  }
 }

  public function index()
 {

  $user = Auth::user();
  return view('Home.index')->withUser($user);

 }

My logout function

public function logout()
 {
  auth()->logout();
  Alert::success('Successfully Logged out');
  return redirect()->route('login_form');
 }

the above function worked fine, i didnt use any athentication package or anything else.

just in my nav bar i would check like this and it worked.

 @if( auth()->check() && Auth::user()->user_type == "emp")
 {
     show these nav bars
 }

I dont know about middle ware etc. kindly suggest you ideas for this multiple authentication please.

0 likes
6 replies
AbdulBazith's avatar

@alkut thank you for your reply.

actually the link which you send it predefined roles am i right?? admin and writer??

But my application the management decides the roles, involved. there may be 3 roles, 4 roles, or n number of roles with different permissions, so what can i do??

i decided to use spatie package, which has all i expected. whats your opinion???

Alkut's avatar

I spatie can solve your problem with different roles but will be always one table for authentication.

AbdulBazith's avatar

@alkut is there any problem with that one table?? because i never used spatie package.

just now i started with that, iam not clear about that, referring few tutorials for that..

can you suggest any easy tutorials for that??

AbdulBazith's avatar
AbdulBazith
OP
Best Answer
Level 5

After my reference i fixed Spatie for multiple authentication package.

It works fine for mee

Please or to participate in this conversation.