Vespakoen/authority-laravel — pull request #7 by joecwallace (2012-04-05 15:42:53+00:00)
Title: Tweaking Ability::can()

Hi Koen,

Thanks for the Authority bundle. I'm putting it to good use in a project right now.

This pull request is for a change that I've found very useful in my project, and I thought that other people might find a use for it too.

Let's take a users index page for example. A regular user may only be allowed to see his 'friends' while an admin user may see every user in the system.

We can define a rule like this:

``` php
Authority::allow('index', 'Users', function() use ($user)
{
return $user->is_admin ? DB::table('users')->get() : $user->friends;
});
```

And then in our controller:

``` php
if ($users = Authority::can('index', 'Users'))
{
View::make('index', compact('users'));
}
```

That's a slightly contrived example, but it's easy to imagine other possibilities.

Let me know what you think.

Joe