I have my Laravel auth.php setup with multiple providers and multiple guards.
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'account' => [
'driver' => 'session',
'provider' => 'accounts',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'accounts' => [
'driver' => 'eloquent',
'model' => App\Models\Account::class,
],
],
Within config/backpack/base.php it has an option where you can set 'guard' => null. I'd like to configure this so that it looks at both the account and the web guard and not just the default web guard. I understand I can change this, but I want to allow users with either a web or a account guard to access the backpack admin.
WARNING
I've tested the below up to the point of logging in (with a "user" and an "account" login and everything worked as expected. I've not tested the other auth functionality, ie registration, forgotten password emails, password resets. I expect they will work as is given the below changes but you might need to tweak them a bit if you run into issues, Also, if you allow users with the same credentials in both the
usersandaccountstables, that's probably going to create unexpected results so you'll likely want to prevent that.Assuming you are using all the default Backpack controllers, or at least havent modified them much...
One way accomplish this would be to do the following:
run
composer require funkjedi/composer-include-filessee here, this will allow you to load your own helper file before Backpack tries to load its helper functions.create a custom helper file at
app/Helpers/Backpack.phpwith this content:Update your composer.json file like so:
create a custom login controller at
app/Http/Controllers/Admin/Auth/LoginController.phpwith this content (or wherever you want, just adjust the later steps if you put it elsewhere)inside
routes/backpack/custom.php(create if it doesnt exist) add this code, notice that here we are including all the default Backpack routes but then we comment out the Login route and at the bottom, we add our own login route pointing to the controller we created above: