Multi Login System in Laravel

In this blog, we will show you create multiple login systems in Laravel development. Please read the steps thoroughly. So, let’s start.

When we use Auth for default login this time we are confused about how we can log in to our project's frontend login and backend login.

So, in this case, some developer is going to divide two different projects. But here I will show you how to create in your project using different guard making multiple logins.

Step 1: Customer kernel middleware created from CMD.

php artisan make:middleware customerMiddleware
'customer' => \App\Http\Middleware\customerMiddleware::class,

Step 2: Add this in your routes/web.php

Route::get('/customer/login', 'Customer\FrontController@index')->name('customer.login');

Route::get('/customer/register', 'customer\FrontController@register')->name('customer.register');

Route::post('/customer/login', 'Customer\Auth\LoginController@customerLogin')->name('customer.loginsubmit');

Route::post('/customer/register', 'Customer\Auth\RegisterController@create')->name('customer.registersubmit');

Step 3: Create Customer Guard

'customer' => [

     'driver' => 'session',

     'provider' => 'customers',

   ],

Step 4: Create Customer Provider

'customers' => [
     'driver' => 'eloquent',
     'model' => App\Customer::class,
   ],

Step 5: Create a Customer model under App/customer.php

Step 6: Then changes on app/http/middleware/RedirectIfAuthenticated.php file

if (Auth::guard('customer')->check()) {
     return redirect('/customer/home');
   }

Conclusion:

The above code is personally written and tested by me. It works fine for me. Please share your views in the comment section. See you on my next blog.

We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.