-
-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: auth guard with multiple dynamic auth models #605
Conversation
Thank you. |
@szepeviktor @canvural I've finished a feature that dynamically resolves the actual guard (from Like these (note the // config/auth.php
// 'guards' => [
// ...
// 'admin' => [
// 'driver' => 'session',
// 'provider' => 'admins',
// ],
// ],
// 'providers' => [
// ...
// 'admins' => [
// 'driver' => 'eloquent',
// 'model' => App\Admin::class,
// ],
// ],
public function testGuardAdminUser(): ?Admin
{
return Auth::guard('admin')->user();
}
public function testAuthGuardAdminParameterUser(): ?Admin
{
return auth('admin')->user();
} Should I wait for this merge or add the commit for this PR? |
@szepeviktor @canvural I've finished editing this PR. Added all the stuff for the dynamic guard return type feature. :) |
@canvural Have you had a chance to look at this yet? |
Sorry no. I'm on holiday. I'll take a look next week 👍 |
All right, have fun! 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! I left some comments. Other than that, it looks good!
@canvural thanks for your feedback! I've fixed your comments, please check it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good 👍
Changes
This PR handles the
Guard
interface and extracts the actual guard specified with, after the guard is extracted it loads the matching auth model (through the guard provider) from config and sets the return type (e.g.User
,Admin
,Customer
...).There are 2 new files added for tests
app/Admin.php
andconfig/auth.php
.(I've also added
LoadsAuthModel
trait, sincegetDefaultAuthModel()
is implemented multiple times.)Some example errors before this PR: