Fix role model guard filtering in hasRole checks
Merged
SE
2d ago+22+22+01234567890123456789-8-8-0123456789
Fixes #2977
Reproduction
When a user has an assigned Role model on the web guard, hasRole($role, 'admin') and hasAllRoles($role, 'admin') returned true. The equivalent name and key checks returned false.
Change
- Apply the optional guard filter before matching a
Rolemodel in both methods. - Add a regression test for direct
Roleinput and thehasRole([$role], $guard)path.
Changed files:
src/Traits/HasRoles.phptests/Traits/HasRolesTest.php
Verification
- The regression test failed before the fix (
truereceived wherefalsewas expected). HasRolesTest.phpandTeamHasRolesTest.php: 133 passed, 430 assertions, in the isolated PHP 8.5.11 container. PHPUnit reported one deprecation for the--do-not-cache-resultoption.git diff --checkpassed.- Project patch policy accepted the 2-file, 14-line text-only patch.