Hello Artisan
In this tutorial i will discuss about Laravel custom login with custom guard. To create this laravel multiple guards authentication setup and login i will use doctors table without user model. We know that Laravel uses User model to create default authentication.
So in this laravel custom guard tutorial we will see how we can setup and create our custom guard and make a custom login and logout system in Laravel. Having finished this Laravel custom guard tutorial you will be able to make laravel multi auth in your application.
Laravel uses web as default guard and auth uses as default auth middleware to check whether a user is logged in or not. We will use our own guard to define custom guard name and will create a custom login and logout system with this guard.
So let's see how we can create login system using guard. I have already created this tutorial for Laravel 5. You can see that. In that tutorial i used User model. So you can read also.
Read also : Laravel Multi Auth | Multiple Authentication in Laravel
App\Model\Doctor.php
And in migrations file, paste this below code.
Step 3 : Setup or Create Custom Guard
In this step we need to create our custom guard name. So visit config/auth.php and create your own guard name as many as you want.
config/auth.php
Step 4: Create Route
Now in this step we have to create our route for create Laravel multi auth using guard. Let's create our route.
routes/doctor.php
Now we have to define our custom route path from route service provider. So change it like below.
Step 5: Create Controller
Now in this step you have to create our login controller and method which are defined in doctor.php route. So let's create those method.
App\Http\Controllers\Doctor\Auth\LoginController.php
Now paste this in your helper.php file.
app\helper.php
Now almost all are set to. We have to just create our blade view.
Step 6: Create Blade
Now just paste this html code in this following path to create login system in Laravel using custom guard.
resources/views/doctor/auth/login.blade.php
for logout, use this route and form
Hope you have understand this example tutorial. You can create as many guard as you want from config/auth.php and have to make login system using those custom guard. You can use User model or you can use other model. It doesn't matter.
Link: https://www.codecheef.org/article/laravel-8-login-with-custom-guard-example
No comments:
Post a Comment