You can implement it with out package, it’s so easy. https://pusher.com/tutorials/multiple-authentication-guards-laravel
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.
After my reference i fixed Spatie for multiple authentication package.
It works fine for mee
Please or to participate in this conversation.