New
-
Support for Laravel 5.3
-
Support for PHP 7.1
-
Added
can
,cannot
andcant
methods on roles, to check abilities directly on a role. d1b1187 -
New
IsRole
andIsAbility
traits, so that custom models don't have to extend Bouncer's models. 151094d -
New
define
method on theBouncer
class, to allow defining callbacks on the gate. 9f7d0c3 -
Roles and Abilities now have a
title
column, to optionally add a display name. 558f693Usage:
// Creating a role with a title $role = Bouncer::role()->create([ 'name' => 'site-admin', 'title' => 'Site Administrator', ]); Bouncer::allow($role)->to('delete', Post::class); // Creating an ability with a title $ability = Bouncer::ability()->create([ 'name' => 'ban-users', 'title' => 'Ban users', ]); Bouncer::allow($user)->to($ability); // Creating an ability for a model with a title $ability = Bouncer::ability()->createForModel(Post::class, [ 'name' => 'edit', 'title' => 'Edit posts', ]); Bouncer::allow($user)->to($ability);
Breaking Changes
-
Removed the
Authorize
middleware andAuthorizesResources
trait, since they'e been merged directly into Laravel 0c2ceaa -
Renamed
$user->is($role)
to$user->isAn($role)
and$user->isA($role)
, for compatibility with Laravel 5.3. 145bf65 -
There are also some schema changes, to prepare for upcoming features. The goal is to not need any more schema changes from this point till the launch of 1.0 (we'll see).
If you're upgrading from 0.x to alpha 2, follow the upgrade guide in the docs.
If you're upgrading from alpha 1 to alpha 2, run this migration:
Schema::table('abilities', function (Blueprint $table) { $table->string('name', 150)->change(); $table->string('entity_type', 150)->nullable()->change(); $table->string('title')->nullable()->after('name'); $table->boolean('only_owned')->default(false)->after('entity_type'); $table->dropUnique('abilities_name_entity_id_entity_type_unique'); $table->unique(['name', 'entity_id', 'entity_type', 'only_owned']); }); Schema::table('roles', function (Blueprint $table) { $table->string('title')->nullable()->after('name'); $table->integer('level')->unsigned()->nullable()->after('name'); });