I created two different login forms with two different register forms and two different tables ,at the moment i can do the following
Login into table A(users)
Register into table A(users)
Register into table B(students)
But i can't logon on table B ,is like it is getting confused on which table to logon .I just modified the auth built-in functionality
Here is my code function for login under
public function postLoginl(Request $request)
{
$this->validate($request, [
'learnerCell'=> 'required', 'password' => 'required',
]);
$credentials = $this->getCredentialsl($request);
if (Auth::attempt($credentials, $request->has('remember'))) {
return redirect()->intended($this->redirectPath());
}
return redirect($this->loginPath())
->withInput($request->only('learnerCell', 'remember'))
->withErrors([
'learnerCell' => $this->getFailedLoginMessage(),
]);
}
When I check on config/auth.php there is a script
<?php
return [
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'users',
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
];
of which i think is where the problem lies,because it does not have model to control the login it only references one model (User) and I have another one called (Learner).
I assume you're using Laravel 5.1 - let me know if it's not true and I'll try to help you with other version as well.
Easiest way to do this is to store users in a single table with additional type flag. I understand that you want to have 2 different login processes and different credentials to be used for login. Once you have users in the same table the way to do that is:
It can be done as below,
Under
app\Http\Controllers\Student
createAuthCotroller
as below. This controller will handle student authentication.Now create following middleware,
Now in
app/Http/kernel.php
register above middleware with other middleware as below,now in
routes.php
create following routes group with middlewareuser.student
,I hope you have already created
Student
model andstudents
table which should essentially be at least same as ausers
table. Now, while you access route withstudent
prefix,user.student
middleware will jumps in and changes the authentication table tostudents
and model toStudent
on the fly. You can even have different session forstudent
as I have already shown.Under
view
directory you can put all student related views understudent
directory. I assume you have separate login form for student which you should create underview\student
directory.This way you can completely separate
student
section fromusers
section. I hope it helps.