Public demo: nothing is sent to any provider and the data resets regularly.

Access

Two ways to say who may do what. Bouncer keeps abilities and roles in four tables (prefixed bouncer_, because both packages would create a roles table), Laratrust keeps roles and permissions in its own. The seeder gave the three users the same rules in both, and the matrices below ask each package through its own API.

bouncerlaratrust
Both packages give the same answer for every user and ability.

Bouncer

Userposts.viewposts.editposts.deleteusers.manage
Ada Adminadmin allowed allowed allowed allowed
Emre Editoreditor allowed allowed denied denied
Rita Readerreader allowed denied denied denied

Computed with bouncer.From(ctx).Can(ctx, entity, ability).

Laratrust

Userposts.viewposts.editposts.deleteusers.manage
Ada Adminadmin allowed allowed allowed allowed
Emre Editoreditor allowed allowed denied denied
Rita Readerreader allowed denied denied denied

Computed with laratrust.From(ctx).User(subject).IsAbleTo(ctx, permission).

Middleware

Bouncer: CanAbility

route.Middleware(bouncer.CanAbility[Member]{Ability: "posts.edit"}).
    Get("/bouncer", handler)

Guests get 401, users without the ability 403. Try the route as each user:

Laratrust: Permission

route.Middleware(laratrust.Permission[Member]("posts.edit")).
    Get("/laratrust", handler)

A user without the permission gets the abort code of LARATRUST_ABORT_CODE (403).

The demo has no login form, so a small middleware signs in the user named by ?as= for these two routes only. A real application would use its session guard.

Özkan Özcan

Available for new projects

Hire the developer behind these packages

I am Özkan Özcan. I ported, tested and published every package in this demo, and I can do the same for your code:

  • Port your Laravel package or application to Laravel Go
  • Move one slow service first and keep the rest in PHP
  • Priority support and custom features for any OzSuite package
Start a project See my services

I reply within one working day.