Skip to content

Commit

Permalink
[3.0] Add Laravel 6.0 support (drops L5.7 and older)
Browse files Browse the repository at this point in the history
Now requires Laravel 5.8 and newer, and PHP 7.2 and newer.
Older Laravel versions can use prior versions of this package.
  • Loading branch information
drbyte committed Sep 2, 2019
1 parent 45826bd commit 5bac232
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
vendor
tests/temp
.idea
.phpunit.result.cache
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## 3.0.0 - 2019-09-02
- Update dependencies to allow for Laravel 6.0
- Drop support for Laravel 5.7 and older, and PHP 7.1 and older. (They can use v2 of this package until they upgrade.)
To be clear: v3 requires minimum Laravel 5.8 and PHP 7.2


## 2.37.0 - 2019-04-09
- Added `permission:show` CLI command to display a table of roles/permissions
- `removeRole` now returns the model, consistent with other methods
Expand Down
37 changes: 21 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "spatie/laravel-permission",
"description": "Permission handling for Laravel 5.4 to 5.8",
"description": "Permission handling for Laravel 5.8 and up",
"keywords": [
"spatie",
"laravel",
"permission", "roles", "permissions", "rbac",
"permission",
"permissions",
"roles",
"acl",
"rbac",
"security"
],
"homepage": "https://github.com/spatie/laravel-permission",
Expand All @@ -19,15 +22,15 @@
}
],
"require": {
"php" : ">=7.0",
"illuminate/auth": "~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"illuminate/container": "~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"illuminate/contracts": "~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"illuminate/database": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0"
"php" : "^7.2",
"illuminate/auth": "^5.8|^6.0",
"illuminate/container": "^5.8|^6.0",
"illuminate/contracts": "^5.8|^6.0",
"illuminate/database": "^5.8|^6.0"
},
"require-dev": {
"orchestra/testbench": "~3.4.2|~3.5.0|~3.6.0|~3.7.0",
"phpunit/phpunit": "^5.7|6.2|^7.0",
"orchestra/testbench": "^3.8",
"phpunit/phpunit": "^8.0",
"predis/predis": "^1.1"
},
"autoload": {
Expand All @@ -43,17 +46,19 @@
"Spatie\\Permission\\Test\\": "tests"
}
},
"scripts": {
"test": "phpunit"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Spatie\\Permission\\PermissionServiceProvider"
]
}
}
},
"scripts": {
"test": "phpunit"
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: v2
title: v3
slogan: Associate users with roles and permissions
githubUrl: https://github.com/spatie/laravel-permission
branch: master
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-usage/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 4

Role and Permission data are cached to speed up performance.

While we recommend not changing the cache "key" name, if you wish to alter the expiration time you may do so in the `config/permission.php` file, in the `cache` array. Note that as of v2.26.0 the `cache` entry here is now an array, and `expiration_time` is a sub-array entry.
While we recommend not changing the cache "key" name, if you wish to alter the expiration time you may do so in the `config/permission.php` file, in the `cache` array.

When you use the built-in functions for manipulating roles and permissions, the cache is automatically reset for you, and relations are automatically reloaded for the current model record:

Expand Down
15 changes: 9 additions & 6 deletions docs/advanced-usage/extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ title: Extending
weight: 3
---


If you are extending or replacing the role/permission models, you will need to specify your new models in the configuration.
First be sure that you've published the configuration file (see the Installation instructions), and edit it to update the `models.role` and `models.permission` values to point to your new models.

Note the following requirements when extending/replacing the models:


### Extending
If you need to EXTEND the existing `Role` or `Permission` models note that:

- Your `Role` model needs to extend the `Spatie\Permission\Models\Role` model
- Your `Permission` model needs to extend the `Spatie\Permission\Models\Permission` model

### Replacing
If you need to REPLACE the existing `Role` or `Permission` models you need to keep the
following things in mind:

- Your `Role` model needs to implement the `Spatie\Permission\Contracts\Role` contract
- Your `Permission` model needs to implement the `Spatie\Permission\Contracts\Permission` contract

In BOTH cases, whether extending or replacing, you will need to specify your new models in the configuration. To do this you must update the `models.role` and `models.permission` values in the configuration file after publishing the configuration with this command:

```bash
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"
```

2 changes: 1 addition & 1 deletion docs/advanced-usage/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 1
In your application's tests, if you are not seeding roles and permissions as part of your test `setUp()` then you may run into a chicken/egg situation where roles and permissions aren't registered with the gate (because your tests create them after that gate registration is done). Working around this is simple: In your tests simply add a `setUp()` instruction to re-register the permissions, like this:

```php
public function setUp()
public function setUp(): void
{
// first include all the normal setUp operations
parent::setUp();
Expand Down
38 changes: 23 additions & 15 deletions docs/basic-usage/blade-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,29 @@ title: Using Blade directives
weight: 4
---

This package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.
#### Blade and Permissions
This package doesn't add any **permission**-specific Blade directives.
Instead, use Laravel's native `@can` directive to check if a user has a certain permission.

```php
@can('edit articles')
//
@endcan
```
or
```php
@if(auth()->user()->can('edit articles') && $some_other_condition)
//
@endif
```

You can use `@can`, `@cannot`, `@canany`, and `@guest` to test for permission-related access.


### Roles
As discussed in the Best Practices section of the docs, it is strongly recommended to always use permission directives, instead of role directives.

However, in case you need to test for Roles, this package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.

Optionally you can pass in the `guard` that the check will be performed on as a second argument.

Expand Down Expand Up @@ -65,17 +87,3 @@ Alternatively, `@unlessrole` gives the reverse for checking a singular role, lik
@endunlessrole
```

#### Blade and Permissions
This package doesn't add any permission-specific Blade directives. Instead, use Laravel's native `@can` directive to check if a user has a certain permission.

```php
@can('edit articles')
//
@endcan
```
or
```php
@if(auth()->user()->can('edit articles') && $some_other_condition)
//
@endif
```
6 changes: 3 additions & 3 deletions docs/installation-laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Installation in Laravel
weight: 4
---

This package can be used in Laravel 5.4 or higher. If you are using an older version of Laravel, take a look at [the v1 branch of this package](https://github.com/spatie/laravel-permission/tree/v1).
This package can be used in Laravel 5.8 or higher.

You can install the package via composer:

Expand All @@ -20,7 +20,7 @@ The service provider will automatically get registered. Or you may manually add
];
```

You can publish [the migration](https://github.com/spatie/laravel-permission/blob/master/database/migrations/create_permission_tables.php.stub) with:
You must publish [the migration](https://github.com/spatie/laravel-permission/blob/master/database/migrations/create_permission_tables.php.stub) with:

```bash
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
Expand All @@ -41,7 +41,7 @@ You can publish the config file with:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"
```

When published, [the `config/permission.php` config file](https://github.com/spatie/laravel-permission/blob/master/config/permission.php) contains:
When published, [the `config/permission.php` config file](https://github.com/spatie/laravel-permission/blob/master/config/permission.php) initially contains:

```php
return [
Expand Down
6 changes: 4 additions & 2 deletions docs/installation-lumen.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ title: Installation in Lumen
weight: 4
---

You can install the package via Composer:
NOTE: Lumen is not officially supported by this package. However, the following are some steps which may help get you started.

First, install the package via Composer:

``` bash
composer require spatie/laravel-permission
Expand Down Expand Up @@ -33,7 +35,7 @@ $app->routeMiddleware([
]);
```

As well as the config file, service provider, and cache alias:
Also register the config file, service provider, and cache alias:

```php
$app->configure('permission');
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $role->givePermissionTo('edit articles');

If you're using multiple guards we've got you covered as well. Every guard will have its own set of permissions and roles that can be assigned to the guard's users. Read about it in the [using multiple guards](#using-multiple-guards) section of the readme.

Because all permissions will be registered on [Laravel's gate](https://laravel.com/docs/5.5/authorization), you can check if a user has a permission with Laravel's default `can` function:
Because all permissions will be registered on [Laravel's gate](https://laravel.com/docs/authorization), you can check if a user has a permission with Laravel's default `can` function:

```php
$user->can('edit articles');
Expand Down
3 changes: 3 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ title: Upgrading
weight: 4
---

### Upgrading from v2 to v3
There are no special requirements for upgrading from v2 to v3, other than changing `^2.xx` (xx can vary) to `^3.0` in your `composer.json` and running `composer updat`. Of course, your app must meet the minimum requirements as well.

### Upgrading from v1 to v2
If you're upgrading from v1 to v2, there's no built-in automatic migration/conversion of your data.
You will need to carefully adapt your code and your data manually.
Expand Down
2 changes: 1 addition & 1 deletion tests/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class BladeTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CacheTest extends TestCase

protected $registrar;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MiddlewareTest extends TestCase
protected $permissionMiddleware;
protected $roleOrPermissionMiddleware;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class RoleTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class RouteTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class TestCase extends Orchestra
/** @var \Spatie\Permission\Models\Permission */
protected $testAdminPermission;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down

0 comments on commit 5bac232

Please sign in to comment.