I almost lost hope implementing multi auth in laravel, clutching at bogus tutorials and hitting dead ends until I saw this tutorial and everything changed. Thank you Alex, keep up the good work..
@DevMarketer thank you very much for this walk through. Very informative and professionally done. I just wanted to add my 2 cents after struggling with custom multiple auth controllers, guards and middleware. I believe it is important to avoid overriding built-in Laravel functionality where possible, from many reasons but the most important one is to that you minimize the risk that your authentication will break in future versions . I've found that Instead of re-creating the whole login method inside the controller (which is inherited from the `AuthenticatesUsers` trait), it's easier to add a `guard` method to the custom login Controller that returns `Auth::guard('admin')`- this assumes that the credentials field names are the same of course. This way we use the build in login method and if it ever gets changed in the framework nothing breaks (my project starts as early as Laravel 4 an I saw way too many changes to the authentication methods). Hope it makes sense and helps someone. Keep up the good work!
Thank you very much for these tutorials about multi-auth. You made the most straight forward and easy to understand tutorials on this topic and I have seen many. Your way of explaining things is very good and you are definitely well prepared!
I'm just learning Laravel , and this tutorial was very useful to learn how to make a good login and then implemented in on my app ^.^, Greetings from Mexico !
Hey You are awesome. The way you explained everything makes understanding so easy. Thanks for creating such helpful series.I have gone through number of other tutorials but finally i found you the best.
login page is unable to display . it shows error 'ReflectionException (-1) Class App\Http\Controllers\Auth\AdminController does not exist' please am using laravel 5.8.This tutorial is really indeed a great tutorial.keep it up Devmarketer
Man, cool videos! I was looking to this kind of tutorial like 3 weeks! I'm nooby with laravel so this will be so useful to me. By the way, I noticed you used to get some files going through the files. I think you're using Sublime so you can hint CTRL+P and type the file you are looking for. That could be save you a few seconds on your videos. Keep working like this, man! You're going great!
Hey, great tutorial! you explain everything really well, 1) I do have minor problems though it seems to me a few other viewers have the same problem but it has not been answered. so when you are at admin/login then you enter your details for admin it should redirect to another page (admin.dashboard). instead it takes you back to the same page(login form), after troubleshooting abit even if you enter a wrong password it does not show any errors which is odd as the register page works fine and shows errors when one occurs. what would you do to fix these problems? 2) I would like to use the admin table for admins to register themselves but after messing around i cannot find which bit to tweak to direct the register logic to admin table instead of the users one. Thanks
It is super important to use throttling security for multiple login attempts for a website that is live on the internet. Bots are constantly searching for websites that the bots can use password rainbow lists and brute force to get in to your site. My suggestion is to never ever remove throttling features from Laravel. You must be meaning that you wont be creating the error pages and the user support for displaying timeout throttling messages etc. My guess is that you are focusing on creating the login part and not UI for throttling errors. I think its important that you make that clear to the viewer. Maybe put a little disclaimer box in the video.
Thank you very much your video series help me a lot to make my project but you have used 5.x of laravel version and it also work in laravel 7 in my case thanks again
hi, the only problem i am facing is that it is not directing me to the 'admin dashboard' . Even with correct password ....? what should i do ? plz help soon
Make sure the columns in the database are in small letters, the input names on your forms in small letters too, also make sure this matches the input fields in your controller. I did this and it worked for me.
Yes , i have figured out the issue. the password must be encrypted and then save into your database. it should not be enter manually. Either use 'Tinker' to save username or password. or in your 'Controller' use this to save the password = $clinics->password = bcrypt($request->password);... $clinics is a object name ... password is a column name in my database and this line of code is bycypt($request->password) is where i am taking request from the textfield. hope this helps ! Good luck!!
is it ok to use middleware in web.php? like Route::group(['prefix' => 'admin', 'middleware' => 'auth:admin'],function () {} I think its more clear than controller
Hey! I have been following "How to build a blog" series, but using laravel 5.4. So when it comes to authentication parts (part 27) I decided to follow this tutorial instead because of the differences between the version that is used in that tutorial and version 5.4. So, right now doing everything in this video got me a "FatalThrowableError in AdminLoginController.php line 25: Class 'App\Http\Controllers\Auth\Auth' not found " error. What is causing this?
Hi, thanks allot for your time and marvelous channel. looked everywhere on how modal login will work with Laravel, but not success. hope that you cover or guide this area.
Hi, Your video is very helpful the only problem i found is, when accessing /admin without login, it is redirecting me to /login page. It should login to /admin/login ..... hope you understand my concern and will get your answer soon.
@DevMarketer so i needed to implement this on my final year project at school and i happened to find this. now, everything works from part one but in part two when in input the credentials for the admin, it redirects me back to the adminlogin page. some people had these erros. was the a solutions or can you help me put here?
Hi There, I have got multi auth working thanks to this tutorial. Access, however, seems to be a bit of a problem. I have a controller that needs to be guarded by both, user and admin, meaning that only these types of users can access this controller, but every time I use one guard in __construct(), the other cannot access it. I even tried $this->middleware(['auth','auth:admin']) and both types got blocked from accessing this controller. Thank you already for this great series.
why we using 2 different routes for 2 types of login?? we should have the same routes for login for both user and admin. while checking data from database, we should check from both table & based on that we will divide either as user or admin. How to do this?
hello...may I know how to differentiate admin and user registration.when I register it is saving into user table but not admin table based on your tutorial.
Hi. This is really good and helpful. Can you please explain how can I implement validation for admin login form? As the error message is not displayed when wrong credentials are entered.
Hey Dev how are you. Dev i am unable to verify credentials, every single time it returns back to admin login page. If(Auth...) not working at all. I've checkd and go through my code again and agiain but can't find an issue. Please guide.
It seems for me may be the admin guard is not caught in the handler class so it is not authenticating me as admin instead it lets me go forward with the request and show the admin dashboard page.
when password resets are coming? very awesome tutorial Alex.. thank you.. please make a video on multi role users.. please.. or extend this series... thank you.
Firstly thank you so much. I have a query. Tinker gives error 'Class 'Illuminate\Foundation\Auth\Admin' not found' when I try to create a new admin as you did. So, I had to create an Admin class similar to User class in this directory. Then it works. Is this the correct way?? Please help.
need some help here at your video 10:26 for the file AdminLoginController 'use Illuminate\Http\Request;' i get a message 'import illuminate http request is never used' so when i execute my code i get some error message as they can't use $request my laravel version 5.7
Hi - Fantastic series by the way. Thank you. I am following the tutorial but I am getting 'undefined class Auth' when I use ... namespace App\Http\Controllers\Auth; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Auth; --------- Any ideas what I am doing wrong ?
I know it's an old video, but I have a question Alex : I can't log 2 different types of users in the same time. When I'm loggued in with an admin, as soon as I try to log with a customer, the admin is loggued out. Do you have any lead (maybe you've faced the problem at one point) of the issue ? Thanks (you do awesome videos!)
SO I am following the steps you created for an admin, I need our admins to login with two different numbers. an employee number and department number. We are not using passwords. i was able to get setup correctly I am testing it out now but the when I add the department number it does not re direct to the dashboard it just jumps and stays on the login. Is there a step I am missing?
Sir how to get multi auth user data. For example if user a is login then get user a id from Auth::user()->id. So on if login b user get this user data.
i stopped at 7:05 and confused, the architecture already diffrent, LOL, i think laravel updated again, i'm in laravel 5.4 (17-may-2017) they have more folder inside /illuminate/Auth/ and diffrent naming and code as well, so i will watch your video and clone your github, thx for made this video
I completed till this video everything had worked until at the end when i login as admin even if i enter valid credentials that redirect back command is executed and to rule out the possiblity that i did some mistake i again made new laravel project and again watched the video and did it still the same thing happened. can someone tell me what is the problem and how i can fix this.
All of this is nice, but woudnt be just easyer on the LoginAdminController simply call a method guard from the AuthenticatesUsers controller and set it to the 'admin' /** * Get the guard to be used during authentication. * * @return \Illuminate\Contracts\Auth\StatefulGuard */ protected function guard() { return Auth::guard('admin'); }
~Hi Mauro. I'm not able to login in with this code on the admin login. It seems it fails the login becaus i get redirected to the admin login page with the email data. So that autentication is not successeful i don't know why. How can i implement your solution?
I got this error when login to admin "Argument 1 passed to App\Http\Controllers\Controller::validate() must be an instance of Illuminate\Http\Request, string given, called in C:\xampp\htdocs\multiauth\app\Http\Controllers\Auth\AdminLoginController.php
If I had multiple admins and each one have separate job_title, How could I separate them in controller so admin with administrator job_title can access some controllers and another admin with supervisor can access another controller? help plz
Hey, Alex. Nice tutorial, but I'm wondering why are you copying just a part of AuthenticateUsers trait when you can use it in your AdminLoginController and just add the guard() method that specifies the guard against which you want to log the user (well, admin in this case) in? It's just one method call and you get all the goodies the trait comes with... I did it that way and it works. Any ideas if this is wrong on my side?
Yes i changed my code too at the end, but i think it is good also the way he showed it to us. Personally it helped me to understand some behind the scenes stuff better.
Hi I am using Laravel 5.5 when i use ($this->middleware('guest:student'); ) in AdminLoginController it doesnot allow me to go to localhost:8000/admin/login instead of that it shows me no page found i have defined route for this but it is not working.Can Any one tell me the fix !! By the way when i remove $this->middleware line it allows me to go to localhost/admin/login!!
Hi , after the login i can get user info from auth: auth()->guard('admin')->user(). But when i redirect any page, It seems that it has not been logged. I checked Auth::check() - result is false
I am a programmer from Brazil and even though i am not fluent i can understand the content perfectly!
You are too much a teacher!
I almost lost hope implementing multi auth in laravel, clutching at bogus tutorials and hitting dead ends until I saw this tutorial and everything changed. Thank you Alex, keep up the good work..
Thank you very much you are one of the best teacher and laravel programmer in the world man
Been struggling with Admin authentication for days until I found this lesson. Thanks so much!!
@DevMarketer thank you very much for this walk through. Very informative and professionally done. I just wanted to add my 2 cents after struggling with custom multiple auth controllers, guards and middleware. I believe it is important to avoid overriding built-in Laravel functionality where possible, from many reasons but the most important one is to that you minimize the risk that your authentication will break in future versions . I've found that Instead of re-creating the whole login method inside the controller (which is inherited from the `AuthenticatesUsers` trait), it's easier to add a `guard` method to the custom login Controller that returns `Auth::guard('admin')`- this assumes that the credentials field names are the same of course. This way we use the build in login method and if it ever gets changed in the framework nothing breaks (my project starts as early as Laravel 4 an I saw way too many changes to the authentication methods). Hope it makes sense and helps someone. Keep up the good work!
Thank you very much for these tutorials about multi-auth. You made the most straight forward and easy to understand tutorials on this topic and I have seen many. Your way of explaining things is very good and you are definitely well prepared!
I'm just learning Laravel , and this tutorial was very useful to learn how to make a good login and then implemented in on my app ^.^, Greetings from Mexico !
Hey You are awesome. The way you explained everything makes understanding so easy. Thanks for creating such helpful series.I have gone through number of other tutorials but finally i found you the best.
Clear. Professional. Perfect. You're my first choice for Laravel.
Your teaching skill is super......Thank You man
Watching this now, because former employee used this in 2 real projects and now I need to modify that projects. He linked me here.
login page is unable to display . it shows error 'ReflectionException (-1)
Class App\Http\Controllers\Auth\AdminController does not exist'
please am using laravel 5.8.This tutorial is really indeed a great tutorial.keep it up Devmarketer
i have the same problem did u already find a solution? because i didnt :(
if you really want to create multi auth in laravel, you will need to copy your User.php file and rename it.follow these process:
when i uncomment
//$this->middleware('guest:admin'); in admin controller then it redirected to login page after login from admin login please help
actually finding contentment in learning new cool multi auth functionality.
perfecto, no hablo ingles y entiendo muy bien lo que transmites, excelente!
Man, cool videos! I was looking to this kind of tutorial like 3 weeks! I'm nooby with laravel so this will be so useful to me.
By the way, I noticed you used to get some files going through the files. I think you're using Sublime so you can hint CTRL+P and type the file you are looking for. That could be save you a few seconds on your videos.
Keep working like this, man! You're going great!
Really good video. I would recommend to anyone trying to learn more about laravel login in general.
Hey, great tutorial! you explain everything really well,
1) I do have minor problems though it seems to me a few other viewers have the same problem but it has not been answered.
so when you are at admin/login then you enter your details for admin it should redirect to another page (admin.dashboard). instead it takes you back to the same page(login form), after troubleshooting abit even if you enter a wrong password it does not show any errors which is odd as the register page works fine and shows errors when one occurs.
what would you do to fix these problems?
2) I would like to use the admin table for admins to register themselves but after messing around i cannot find which bit to tweak to direct the register logic to admin table instead of the users one.
Thanks
It is super important to use throttling security for multiple login attempts for a website that is live on the internet. Bots are constantly searching for websites that the bots can use password rainbow lists and brute force to get in to your site. My suggestion is to never ever remove throttling features from Laravel. You must be meaning that you wont be creating the error pages and the user support for displaying timeout throttling messages etc. My guess is that you are focusing on creating the login part and not UI for throttling errors. I think its important that you make that clear to the viewer. Maybe put a little disclaimer box in the video.
What is a throttling feature?
dude first video's link is incorrect, please correct it. you are owersome becouse explanation is fantastic
Thank you very much your video series help me a lot to make my project but you have used 5.x of laravel version and it also work in laravel 7 in my case thanks again
Thank you so much, what a beneficial video. Note! In your video descriptions, Part 1's links are wrong. Thank you again.
That creepy sound at 14:53 and that mysterious look following it.. LOL :)
Thank you. Your first video made me realize of something. :)
Hi,
Great tutorial!! got my Multi Auth implemented. Just one question:
How can I redirect the admin logout to the admin login page ?
Thank you!
Hi, I get an error when I want to logout as admin, then the admin site address is still accessible. What should I do ?
Thank you for this series! Any idea when part 4 will be available?
Your videos are helping me a lot. Thanks Man.
Thank you, that was just what I needed. Awesome, keep up the vids!
this is immeasurably helpful. Thank you so much
hi, the only problem i am facing is that it is not directing me to the 'admin dashboard' . Even with correct password ....? what should i do ? plz help soon
Experiencing the same problem with laravel 5.3. Did you figure it out?
Make sure the columns in the database are in small letters, the input names on your forms in small letters too, also make sure this matches the input fields in your controller. I did this and it worked for me.
I have the same problem did you solve it ? @mark
Yes , i have figured out the issue. the password must be encrypted and then save into your database. it should not be enter manually. Either use 'Tinker' to save username or password. or in your 'Controller' use this to save the password = $clinics->password = bcrypt($request->password);... $clinics is a object name ... password is a column name in my database and this line of code is bycypt($request->password) is where i am taking request from the textfield. hope this helps ! Good luck!!
ok it is worked thanks @mark
is it ok to use middleware in web.php?
like Route::group(['prefix' => 'admin', 'middleware' => 'auth:admin'],function () {}
I think its more clear than controller
Hey! I have been following "How to build a blog" series, but using laravel 5.4. So when it comes to authentication parts (part 27) I decided to follow this tutorial instead because of the differences between the version that is used in that tutorial and version 5.4.
So, right now doing everything in this video got me a
"FatalThrowableError in AdminLoginController.php line 25:
Class 'App\Http\Controllers\Auth\Auth' not found " error.
What is causing this?
Fixed it: Added "use Illuminate\Support\Facades\Auth;" in "AdminLoginController.php"
thank you sir. you are very helpful!!!!
Thank you sir... Very helpful tutorial.. exactly what i was looking for
Hi,
thanks allot for your time and marvelous channel.
looked everywhere on how modal login will work with Laravel, but not success. hope that you cover or guide this area.
Hi Great tutorial!! got my Multi Auth implemented
Hi, Your video is very helpful the only problem i found is, when accessing /admin without login, it is redirecting me to /login page. It should login to /admin/login ..... hope you understand my concern and will get your answer soon.
i love your video i get all the time what i need nothing more fancy which make confusion...
Thank you for helping me get my degree :)
Hey Alex, learning the most from your videos. Just letting you know the video link for part 1 is incorrect, it's directing to part 2.
Thank you so much great tutorial helps me a lot
Friend, I would give you more likes if it could be done. Very cool and useful video!
Thanks a lot for share your skills with us
The force will be with you
great work! thank you. Can you please create written or video tutorial for complete e-commerce project.
32:15 btw thanks for this video its really helpful.
@DevMarketer so i needed to implement this on my final year project at school and i happened to find this.
now, everything works from part one but in part two when in input the credentials for the admin, it redirects me back to the adminlogin page. some people had these erros. was the a solutions or can you help me put here?
Excellent..... You just made my day
Hi There, I have got multi auth working thanks to this tutorial. Access, however, seems to be a bit of a problem. I have a controller that needs to be guarded by both, user and admin, meaning that only these types of users can access this controller, but every time I use one guard in __construct(), the other cannot access it. I even tried $this->middleware(['auth','auth:admin']) and both types got blocked from accessing this controller. Thank you already for this great series.
why we using 2 different routes for 2 types of login??
we should have the same routes for login for both user and admin.
while checking data from database, we should check from both table & based on that we will divide either as user or admin.
How to do this?
thanks, boss I was looking exactly like that it's working for me in front end and admin both in laravel 5.7
it works in the part of validating the login fields?
This is SO helpful! Thank you.
+++++++
I love you men, muchas gracias por fin pude solucionar el problema del logueo con otro usuario
hello...may I know how to differentiate admin and user registration.when I register it is saving into user table but not admin table based on your tutorial.
did u solve it sandy ?
For people who face the error Auth::guard
please check the middleware of construct
make sure guest:admin not guest::admin
Because, i faced it too.
AuthenticatesUsers.php file not appearing Laravel Framework 7.7.1 (vendor/larvel/framework/src-illuminate/foundation/auth/AuthenticatesUsers.php file not appearing) please advice.
Whats weird is that if i log in as admin it lets me log in again with the user login and after those 2 login form it routes me to admin dashboard
i thought this was part 1 no wonder why i feel like missing something, this is part 2 of the series -_-
Can you give an array of middle to your controller so Admin can access user dashboard too ?
Thanks
dude, you are awesome .. I really appreciate you efforts .. thanks
such a nice tutorial!!! subbed! keep it up lad
Hi. This is really good and helpful. Can you please explain how can I implement validation for admin login form? As the error message is not displayed when wrong credentials are entered.
Any luck on this? been searching without any luck..
Hey Dev how are you. Dev i am unable to verify credentials, every single time it returns back to admin login page. If(Auth...) not working at all. I've checkd and go through my code again and agiain but can't find an issue. Please guide.
It seems for me may be the admin guard is not caught in the handler class so it is not authenticating me as admin instead it lets me go forward with the request and show the admin dashboard page.
your video is awesome!. hello from Japan!!
Very good tutorial. Thank you
when password resets are coming?
very awesome tutorial Alex.. thank you..
please make a video on multi role users.. please.. or extend this series... thank you.
It says app/models/Admin models not found in laravel 8. can you help me?
whats the difference between using auth middleware in the routes grouping and in the controller? I personally prefer it in the routes list
Many thanks sir.
Hiii i need your help. It say's undefined variable index after i click login
Firstly thank you so much. I have a query. Tinker gives error 'Class 'Illuminate\Foundation\Auth\Admin' not found' when I try to create a new admin as you did. So, I had to create an Admin class similar to User class in this directory. Then it works. Is this the correct way?? Please help.
need some help here at your video 10:26 for the file AdminLoginController 'use Illuminate\Http\Request;' i get a message 'import illuminate http request is never used' so when i execute my code i get some error message as they can't use $request my laravel version 5.7
Hi - Fantastic series by the way. Thank you.
I am following the tutorial but I am getting 'undefined class Auth' when I use ...
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
---------
Any ideas what I am doing wrong ?
I've used Illuminate\Support\Facades\Auth and it seems ok.
What has changed since your tutorial or what did I do wrong?
Thank you so much for sharing!
Very informative! Hats off
sir getting this error
The Response content must be a string or object implementing __toString(), "boolean" given.
how it will solved
Hello. Why can I still go to admin dashboard even if I logout the admin account? Thanks for the answer.
why is this not working ?
Auth::guard('admin')->attempt(...................) // admin using passport as the driver
go to config/auth.php and make sure you set your admin guard driver to session and not token, Hope it helps
Thank you for your helpful content
very interesting tutorial very helpful
I need help, when I login as admin, it does not displays the admin name on the top nav bar. Can someone help. Thanks
I know it's an old video, but I have a question Alex : I can't log 2 different types of users in the same time. When I'm loggued in with an admin, as soon as I try to log with a customer, the admin is loggued out. Do you have any lead (maybe you've faced the problem at one point) of the issue ? Thanks (you do awesome videos!)
hi, how can I get the name column in Admin?, because with user is:
$user = Auth::user()->name;
thanks in advance
SO I am following the steps you created for an admin, I need our admins to login with two different numbers. an employee number and department number. We are not using passwords. i was able to get setup correctly I am testing it out now but the when I add the department number it does not re direct to the dashboard it just jumps and stays on the login. Is there a step I am missing?
Thank uu man ur tuto helped me a lot thankss
Thank you so much, a very nice video.
Sir how to get multi auth user data. For example if user a is login then get user a id from Auth::user()->id. So on if login b user get this user data.
i stopped at 7:05 and confused, the architecture already diffrent, LOL, i think laravel updated again, i'm in laravel 5.4 (17-may-2017) they have more folder inside /illuminate/Auth/ and diffrent naming and code as well, so i will watch your video and clone your github, thx for made this video
I completed till this video everything had worked until at the end when i login as admin even if i enter valid credentials that redirect back command is executed and to rule out the possiblity that i did some mistake i again made new laravel project and again watched the video and did it still the same thing happened. can someone tell me what is the problem and how i can fix this.
All of this is nice, but woudnt be just easyer on the LoginAdminController simply call a method guard from the AuthenticatesUsers controller and set it to the 'admin'
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard('admin');
}
~Hi Mauro. I'm not able to login in with this code on the admin login. It seems it fails the login becaus i get redirected to the admin login page with the email data. So that autentication is not successeful i don't know why. How can i implement your solution?
hi i had follow this video... but i face that some problem. how can create Admins table in phpmyadmin
...?
Excellent! Also work with laravel 6
I got this error when login to admin "Argument 1 passed to App\Http\Controllers\Controller::validate() must be an instance of Illuminate\Http\Request, string given, called in C:\xampp\htdocs\multiauth\app\Http\Controllers\Auth\AdminLoginController.php
Hi, how to you configuring throttle in admin login?
If I had multiple admins and each one have separate job_title, How could I separate them in controller so admin with administrator job_title can access some controllers and another admin with supervisor can access another controller? help plz
why should i create an admin table, just for one admin account. I'll go for role based logged in using "users" and "role"
Hey, Alex. Nice tutorial, but I'm wondering why are you copying just a part of AuthenticateUsers trait when you can use it in your AdminLoginController and just add the guard() method that specifies the guard against which you want to log the user (well, admin in this case) in? It's just one method call and you get all the goodies the trait comes with... I did it that way and it works. Any ideas if this is wrong on my side?
Yes i changed my code too at the end, but i think it is good also the way he showed it to us. Personally it helped me to understand some behind the scenes stuff better.
Hi I am using Laravel 5.5 when i use ($this->middleware('guest:student');
) in AdminLoginController it doesnot allow me to go to localhost:8000/admin/login instead of that it shows me no page found i have defined route for this but it is not working.Can Any one tell me the fix !! By the way when i remove $this->middleware line it allows me to go to localhost/admin/login!!
Hi , after the login i can get user info from auth: auth()->guard('admin')->user(). But when i redirect any page, It seems that it has not been logged. I checked Auth::check() - result is false
Hi DevMarketer
Can you please share the handout for these videos please