Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: spatie/laravel-permission
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.11.1
Choose a base ref
...
head repository: spatie/laravel-permission
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6.0.0
Choose a head ref
Loading
Showing with 3,901 additions and 1,381 deletions.
  1. +2 −0 .gitattributes
  2. +1 −1 .github/workflows/dependabot-auto-merge.yml
  3. +3 −3 .github/workflows/fix-php-code-style-issues.yml
  4. +31 −0 .github/workflows/phpstan.yml
  5. +0 −38 .github/workflows/run-tests-L7.yml
  6. +14 −16 .github/workflows/{run-tests-L8.yml → run-tests.yml}
  7. +67 −0 .github/workflows/test-cache-drivers.yml
  8. +2 −2 .github/workflows/update-changelog.yml
  9. +46 −0 CHANGELOG.md
  10. +8 −8 README.md
  11. +15 −13 composer.json
  12. +38 −12 config/permission.php
  13. +15 −18 database/migrations/add_teams_fields.php.stub
  14. +23 −26 database/migrations/create_permission_tables.php.stub
  15. +5 −4 docs/advanced-usage/cache.md
  16. +8 −6 docs/advanced-usage/custom-permission-check.md
  17. +1 −1 docs/advanced-usage/exceptions.md
  18. +39 −12 docs/advanced-usage/extending.md
  19. +1 −1 docs/advanced-usage/other.md
  20. +1 −1 docs/advanced-usage/phpstorm.md
  21. +9 −3 docs/advanced-usage/seeding.md
  22. +24 −11 docs/advanced-usage/testing.md
  23. +4 −5 docs/advanced-usage/timestamps.md
  24. +4 −0 docs/advanced-usage/ui-options.md
  25. +134 −99 docs/advanced-usage/uuid.md
  26. +1 −1 docs/basic-usage/artisan.md
  27. +26 −10 docs/basic-usage/basic-usage.md
  28. +14 −5 docs/basic-usage/blade-directives.md
  29. +11 −2 docs/basic-usage/direct-permissions.md
  30. +103 −0 docs/basic-usage/enums.md
  31. +65 −13 docs/basic-usage/middleware.md
  32. +15 −5 docs/basic-usage/multiple-guards.md
  33. +1 −1 docs/basic-usage/new-app.md
  34. +58 −0 docs/basic-usage/passport.md
  35. +2 −2 docs/basic-usage/role-permissions.md
  36. +26 −5 docs/basic-usage/super-admin.md
  37. +56 −15 docs/basic-usage/teams-permissions.md
  38. +11 −7 docs/basic-usage/wildcard-permissions.md
  39. +12 −5 docs/best-practices/performance.md
  40. +26 −3 docs/best-practices/roles-vs-permissions.md
  41. +23 −15 docs/installation-laravel.md
  42. +12 −8 docs/installation-lumen.md
  43. +11 −6 docs/prerequisites.md
  44. +68 −4 docs/upgrading.md
  45. +2 −0 phpstan-baseline.neon
  46. +20 −0 phpstan.neon.dist
  47. +2 −0 phpunit.xml.dist
  48. +4 −4 src/Commands/CreateRole.php
  49. +22 −20 src/Commands/Show.php
  50. +3 −8 src/Commands/UpgradeForTeams.php
  51. +10 −15 src/Contracts/Permission.php
  52. +11 −17 src/Contracts/Role.php
  53. +7 −5 src/Contracts/Wildcard.php
  54. +7 −3 src/Exceptions/PermissionDoesNotExist.php
  55. +8 −4 src/Exceptions/RoleDoesNotExist.php
  56. +8 −0 src/Exceptions/UnauthorizedException.php
  57. +34 −14 src/Guard.php
  58. +13 −0 src/Listeners/OctaneReloadPermissions.php
  59. +56 −0 src/Middleware/PermissionMiddleware.php
  60. +56 −0 src/Middleware/RoleMiddleware.php
  61. +56 −0 src/Middleware/RoleOrPermissionMiddleware.php
  62. +0 −30 src/Middlewares/PermissionMiddleware.php
  63. +0 −29 src/Middlewares/RoleMiddleware.php
  64. +0 −28 src/Middlewares/RoleOrPermissionMiddleware.php
  65. +19 −31 src/Models/Permission.php
  66. +47 −55 src/Models/Role.php
  67. +114 −91 src/PermissionRegistrar.php
  68. +72 −76 src/PermissionServiceProvider.php
  69. +151 −119 src/Traits/HasPermissions.php
  70. +114 −73 src/Traits/HasRoles.php
  71. +69 −75 src/WildcardPermission.php
  72. +2 −8 src/helpers.php
  73. +0 −23 tests/Admin.php
  74. +64 −4 tests/BladeTest.php
  75. +9 −7 tests/CacheTest.php
  76. +19 −15 tests/CommandTest.php
  77. +1 −1 tests/CustomGateTest.php
  78. +37 −1 tests/GateTest.php
  79. +136 −13 tests/HasPermissionsTest.php
  80. +116 −2 tests/HasPermissionsWithCustomModelsTest.php
  81. +259 −14 tests/HasRolesTest.php
  82. +89 −1 tests/HasRolesWithCustomModelsTest.php
  83. +0 −33 tests/Manager.php
  84. +44 −1 tests/MultipleGuardsTest.php
  85. +0 −13 tests/Permission.php
  86. +187 −11 tests/PermissionMiddlewareTest.php
  87. +125 −0 tests/PermissionRegistarTest.php
  88. +2 −1 tests/PermissionTest.php
  89. +49 −0 tests/PolicyTest.php
  90. +0 −13 tests/Role.php
  91. +154 −11 tests/RoleMiddlewareTest.php
  92. +126 −11 tests/RoleOrPermissionMiddlewareTest.php
  93. +17 −2 tests/RoleTest.php
  94. +90 −0 tests/RoleWithNestingTest.php
  95. +8 −27 tests/RouteTest.php
  96. +5 −11 tests/TeamHasPermissionsTest.php
  97. +7 −5 tests/TeamHasRolesTest.php
  98. +117 −15 tests/TestCase.php
  99. +1 −1 tests/TestHelper.php
  100. +10 −0 tests/TestModels/Admin.php
  101. +21 −0 tests/TestModels/Client.php
  102. +12 −0 tests/TestModels/Content.php
  103. +16 −0 tests/TestModels/Manager.php
  104. +37 −0 tests/TestModels/Permission.php
  105. +63 −0 tests/TestModels/Role.php
  106. +1 −1 tests/{ → TestModels}/RuntimeRole.php
  107. +1 −1 tests/{ → TestModels}/SoftDeletingUser.php
  108. +56 −0 tests/TestModels/TestRolePermissionsEnum.php
  109. +10 −0 tests/TestModels/User.php
  110. +3 −5 tests/{User.php → TestModels/UserWithoutHasRoles.php}
  111. +1 −1 tests/{ → TestModels}/WildcardPermission.php
  112. +44 −1 tests/WildcardHasPermissionsTest.php
  113. +5 −16 tests/WildcardMiddlewareTest.php
  114. +2 −2 tests/WildcardRoleTest.php
  115. +6 −25 tests/WildcardRouteTest.php
  116. +1 −1 tests/resources/views/can.blade.php
  117. +7 −0 tests/resources/views/haspermission.blade.php
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
/tests export-ignore
/.editorconfig export-ignore
/.php_cs.dist.php export-ignore
/phpstan* export-ignore
/.styleci.yml export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore

2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.3.6
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
compat-lookup: true
6 changes: 3 additions & 3 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -11,14 +11,14 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.1.0
uses: aglipanci/laravel-pint-action@2.3.0

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
31 changes: 31 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: PHPStan

on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v2

- name: Install larastan
run: |
composer require "nunomaduro/larastan" --no-interaction --no-update
composer update --prefer-dist --no-interaction
- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
38 changes: 0 additions & 38 deletions .github/workflows/run-tests-L7.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -9,33 +9,27 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.2, 8.1, 8.0, 7.4, 7.3]
laravel: [10.*, 9.*, 8.*]
php: [8.3, 8.2, 8.1, 8.0]
laravel: ["^10.0", "^9.0", "^8.12"]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
- laravel: "^10.0"
testbench: 8.*
- laravel: 9.*
- laravel: "^9.0"
testbench: 7.*
- laravel: 8.*
testbench: 6.23
- laravel: "^8.12"
testbench: "^6.23"
exclude:
- laravel: 10.*
- laravel: "^10.0"
php: 8.0
- laravel: 10.*
php: 7.4
- laravel: 10.*
php: 7.3
- laravel: 9.*
php: 7.4
- laravel: 9.*
php: 7.3
- laravel: "^8.12"
php: 8.3

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -44,6 +38,10 @@ jobs:
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: none

- name: Install dependencies (remove passport)
run: composer remove --dev laravel/passport --no-interaction --no-update
if: matrix.laravel == '^8.12'

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" "mockery/mockery:^1.3.2" "nesbot/carbon:>=2.62.1" --no-interaction --no-update
67 changes: 67 additions & 0 deletions .github/workflows/test-cache-drivers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "Run Tests - Cache Drivers"

on: [push, pull_request]

jobs:
cache:

runs-on: ubuntu-latest

services:
redis:
image: redis
ports:
- 6379/tcp
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: false

name: Cache Drivers

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv, memcache
coverage: none

- name: Install dependencies
run: |
composer require "predis/predis" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction
- name: Execute tests - memcached cache driver
run: |
vendor/bin/phpunit
env:
CACHE_DRIVER: memcached

- name: Execute tests - redis cache driver
run: |
vendor/bin/phpunit
env:
CACHE_DRIVER: redis
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}

- name: Execute tests - database cache driver
run: |
vendor/bin/phpunit
env:
CACHE_DRIVER: database

- name: Execute tests - file cache driver
run: |
vendor/bin/phpunit
env:
CACHE_DRIVER: file

- name: Execute tests - array cache driver
run: |
vendor/bin/phpunit
env:
CACHE_DRIVER: array
4 changes: 2 additions & 2 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main

@@ -21,7 +21,7 @@ jobs:
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4.16.0
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: Update CHANGELOG
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,42 @@

All notable changes to `laravel-permission` will be documented in this file

## 5.11.1 - 2023-10-25

No functional changes. Just several small updates to the Documentation.

**Full Changelog**: https://github.com/spatie/laravel-permission/compare/5.11.0...5.11.1

## 5.11.0 - 2023-08-30

### What's Changed

- [V5] Avoid triggering `eloquent.retrieved` event by @erikn69 in https://github.com/spatie/laravel-permission/pull/2490

**Full Changelog**: https://github.com/spatie/laravel-permission/compare/5.10.2...5.11.0

## 5.10.2 - 2023-07-04

### What's Changed

- Fix Eloquent Strictness on `permission:show` Command by @erikn69 in https://github.com/spatie/laravel-permission/pull/2457

**Full Changelog**: https://github.com/spatie/laravel-permission/compare/5.10.1...5.10.2

## 5.10.1 - 2023-04-12

### What's Changed

- [V5] Fix artisan command `permission:show` output of roles with underscores by @erikn69 in https://github.com/spatie/laravel-permission/pull/2396

**Full Changelog**: https://github.com/spatie/laravel-permission/compare/5.10.0...5.10.1

## 5.10.0 - 2023-03-22

### What's Changed

- Fix delete permissions on Permissions Model by @erikn69 in https://github.com/spatie/laravel-permission/pull/2366

## 5.9.1 - 2023-02-06

Apologies for the break caused by 5.9.0 !
@@ -593,6 +629,11 @@ The following changes are not "breaking", but worth making the updates to your a








```
1. Also this is a good time to point out that now with v2.25.0 and v2.26.0 most permission-cache-reset scenarios may no longer be needed in your app, so it's worth reviewing those cases, as you may gain some app speed improvement by removing unnecessary cache resets.

@@ -646,6 +687,11 @@ The following changes are not "breaking", but worth making the updates to your a








```
## 2.19.1 - 2018-09-14

16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -49,20 +49,20 @@ We invest a lot of resources into creating [best in class open source packages](

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

### Testing

``` bash
composer test
```

### Changelog
## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

### Testing

``` bash
composer test
```

### Security

If you discover any security-related issues, please email [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.
@@ -92,8 +92,8 @@ And a special thanks to [Caneco](https://twitter.com/caneco) for the logo ✨
## Alternatives

- [Povilas Korop](https://twitter.com/@povilaskorop) did an excellent job listing the alternatives [in an article on Laravel News](https://laravel-news.com/two-best-roles-permissions-packages). In that same article, he compares laravel-permission to [Joseph Silber](https://github.com/JosephSilber)'s [Bouncer]((https://github.com/JosephSilber/bouncer)), which in our book is also an excellent package.
- [ultraware/roles](https://github.com/ultraware/roles) takes a slightly different approach to its features.
- [santigarcor/laratrust](https://github.com/santigarcor/laratrust) implements team support
- [ultraware/roles](https://github.com/ultraware/roles) (archived) takes a slightly different approach to its features.
- [zizaco/entrust](https://github.com/zizaco/entrust) offers some wildcard pattern matching

## License
Loading