@pdlbibek Can you please share your routes files web.php and the header.blade.php?
Laravel 6, Multi Auth Routing
Hello everyone,
I've currently implemented multi-auth guard to enable student login. I have a student table and I can successfully log in with the student account and it redirects me to students route (which has a middleware 'middleware'=> 'auth:student'). The redirect is defined in RedirectIfAuthenticated.php.
Now, what I want to do is access other routes, which will be common for every users. But unable to access atm.
-
I tried to access routes with no middleware defined, but it throws "Trying to get property of non-object" error for
auth()->user()which is on header.blade.php (common header file) -
Also, I tried to access routes with
'middleware'=> ['auth', 'auth:student'], cant access the page from either of the user. Routes with only'middleware'=> ['auth:student']works fine for student user, and Routes with only'middleware'=> ['auth']works fine for admin user.
Feel free to ask for any clarification and will be there asap. Thanks
Thanks @fylzero I solved my problem and now I am a bit aware of core concept regarding middlewares & guards. I am afraid that I made this bit unclear but when I said I was using middlewares like this 'middleware'=> ['auth:student'] I meant that I was using the guards with middleware auth and wanted to know how I can pass multiple guards in the middleware so that I can access the routes from multiple guards (i.e. multiple users). But things went towards my another middleware student and I was suggested to use the middleware student which was a wrong process.
So, Here's the part of my routes.php now, where I've used 'auth' middleware with both 'web,student' guards so that I can access the routes from both the users:
Route::group(['prefix'=>'student', 'namespace' => 'Students', 'middleware'=> 'auth:web,student' ], function () {
Route::get('all', 'StudentsController@display')->name('student.all');
Route::delete('all/{id}', 'StudentsController@destroy')->name('student.delete');
Route::post('all', 'StudentsController@store')->name('student.store');
});
Here on 'middleware'=> 'auth:web,student' auth is a middleware whereas 'web' & 'student' are the guards. Hence, 'auth:web,student' means routes are accessible to authenticated users from both web & student guards.
Thanks!
Please or to participate in this conversation.