Bouncer Versions Save

Laravel Eloquent roles and abilities.

v1.0.0-beta.1

7 years ago

New

  • Forbid abilities. You can now forbid abilities for more granular control. https://github.com/JosephSilber/bouncer/commit/865227ba0d0de74661ffe2e3afc79e1926367c9e

    Bouncer::allow($user)->to('delete', Post::class);
    
    $post1 = Post::where('title', 'Regular post')->first();
    $post2 = Post::where('title', 'Very important post')->first();
    
    Bouncer::forbid($user)->to('delete', $post2);
    
    Bouncer::allows('delete', $post1); // true
    Bouncer::allows('delete', $post2); // false
    

    Here's another example:

    Bouncer::allow('superadmin')->everything();
    
    Bouncer::allow('admin')->everything();
    Bouncer::forbid('admin')->toManage(User::class);
    

    The admin role can now do everything, besides managing users.

  • Easily add a title to an ability. You can now pass additional attributes for the ability model being created. https://github.com/JosephSilber/bouncer/commit/7036b52dc293929ce836bab74194bcc574f37718

    Bouncer::allow($user)->to('edit', Post::class, [
        'title' => 'Edit all posts',
    ]);
    
  • Bouncer factory. It is now easier than ever to use bouncer outside of Laravel. https://github.com/JosephSilber/bouncer/commit/a1b7137423bbe2348848cd066ba6ec4faf8a720a

    $bouncer = Bouncer::create();
    
    // use $bouncer
    $bouncer->allow($user)->to('access-dashboard');
    

    You can also pass along a $user instance to be able to check abilities for that user:

    $bouncer = Bouncer::make()->withUser($user)->create();
    
    $bouncer->allows('access-dashboard');
    

Breaking Changes

v1.0.0-alpha.3

7 years ago

New

  • Support Laravel 5.4.31, which broke Bouncer.

  • Greatly enhanced granting multiple roles/abilities at once:

    // Assign multiple roles:
    Bouncer::assign(['admin', 'editor'])->to($user);
    
    // Allow multiple abilities:
    Bouncer::allow($user)->to(['access-dashboard', 'ban-users']);
    
    // Also works with model abilities:
    Bouncer::allow($user)->to(['edit', 'delete'], Post::class);
    Bouncer::allow($user)->to(['edit', 'delete'], $post);
    
    // And even with multiple models:
    Bouncer::allow($user)->to('delete', [Post::class, Category::class]);
    Bouncer::allow($user)->to(['edit', 'delete'], [Post::class, Category::class]);
    
    // Go crazy and pass it an associative array with whatever you want:
    Bouncer::allow($user)->to([
        'create' => Post::class,
        'view'   => User::class,
        'edit'   => $user,
    ]);
    
  • Added a whereIsNot scope to the hasRoles trait.

Breaking Changes

v1.0.0-alpha.2

7 years ago

New

Breaking Changes

  • Removed the Authorize middleware and AuthorizesResources trait, since they'e been merged directly into Laravel https://github.com/JosephSilber/bouncer/commit/0c2ceaa6e8915699de8cc29e92d30d7a50a0efaf

  • Renamed $user->is($role) to $user->isAn($role) and $user->isA($role), for compatibility with Laravel 5.3. https://github.com/JosephSilber/bouncer/commit/145bf653015ce6ba1a9c42999805158ef7c4cc40

  • 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');
    });
    

v1.0.0-alpha.1

8 years ago

New

  • Polymorphic structure: Bouncer now uses a new polymorphic database schema, so that you can attach roles and abilities to any model (see here how to upgrade your schema).

  • Wildcard abilities: you can now use wildcards to allow a wide spread of abilities:

    Bouncer::allow($user)->to('edit', '*');
    
    Bouncer::allows('edit', $post) == true;
    

    For more information on wildcards, see this discussion: #56

  • whereAssignedTo query scope: Role::whereAssignedTo($users) will return all roles assigned to those users.

  • whereCannot query scope: User::whereCannot('edit', Post::class) will return all users that can't edit posts.

Pending

The following is what's holding up the 1.0 stable release:

  • Wildcards in scopes: currently, not all query scopes handle wildcards properly. We need full wildcard support in all query scopes before 1.0 can be released.
  • Wildcard aliases: we need proper alias methods for most of the wildcard operations. See this discussion for more information.
  • Documentation: there are still a lot of things missing from the documentation. I want to properly flesh it out before the 1.0 release.

v0.1.7

8 years ago
  • Fix for Laravel 5.1, where the third argument to the gate's before callback may be missing.
  • Added --prefer-lowest to the Travis matrix to catch these incompatibilities in the future.

v0.1.6

8 years ago

Fix regression for Laravel 5.1, where the arguments were passed in separately.

v0.1.3

8 years ago
  • You can now call Bouncer::exclusive() to have Bouncer deny any abilities that have not been granted via Bouncer. This will cause the Gate to skip any abilities that you have defined in your code.
  • You can now set your own custom table names:
Bouncer::tables([
    'abilities' => 'my_abilities',
    'roles'     => 'my_roles',
]);

v0.1.2

8 years ago
  • Use composite primary key on pivot tables.
  • Use explicit indexes for pivot tables.
  • Support custom primary keys on the users table.

v0.1.1

8 years ago

Support for Laravel 5.2

v0.1.0

8 years ago

You can now scope user queries by whether they have a particular ability:

$users = User::whereCan('view-dashboard')->get();
$users = User::whereCan('delete', $post)->get();
$users = User::whereCan('delete', Post::class)->get();

You can also directly query roles that have specific abilities:

$roles = Bouncer::role()->whereCan('view-dashboard')->get();
$roles = Bouncer::role()->whereCan('delete', $post)->get();
$roles = Bouncer::role()->whereCan('delete', Post::class)->get();

Finally, you can query users on whether they have a specific role:

$users = User::whereIs('admin')->get();
$users = User::whereIs('admin', 'moderator')->get();
$users = User::whereIsAll('reader', 'contributor')->get();