searsaw/Drawbridge — pull request #3 by jimstump (2014-07-25 05:16:25+00:00)
Title: BridgeUser::hasPermission() does not detect permissions given to a user.

I am running the latest version of Laravel 4.1 (version 4.1.30) and found that after assigning a permission to a role, and then that role to a user, I could not detect whether the user had the permission using `$user->hasPermission('can_edit')`.

After some troubleshooting, I found that this was caused by the role ids in the list returned by `BridgeUser::getRolesWithPermission()` being strings. Those role ids were then iterated over and passed to `BridgeUser::checkRole()` who detected the parameter as a string and thus assumed that it was a role name and not a role id. This confusion caused the role to be incorrectly looked up and the check to fail.

The simplest way I saw to solve this was to cast the role ids as integers after they are fetched from the database. This will allow subsequent functions to correctly detect that this was a list of role ids and not a list of role names.

I don't have any real experience creating formal tests, but here is the code that I used to create some roles and permissions (taken straight from the readme documentation):

```php
$user = User::find(1);

$admin = new Role;
$admin->name = 'admin';
$admin->display_name = 'Admin';
$admin->save();

$author = new Role;
$author->name = 'author';
$author->display_name = 'Author';
$author->save();

$edit = new Permission;
$edit->name = 'can_edit';
$edit->display_name = 'Can Edit';
$edit->save();

$view = new Permission;
$view->name = 'can_view';
$view->display_name = 'Can View';
$view->save();

$user->addRole([$admin, $author]);

$admin->addPermission([$edit->id, 'can_view']);
```

Next, I used the following code to check if our user had the 'can_edit' permission:

```php
$user = User::find(1);
dd( $user->hasPermission('can_edit') );
```

This outputs `boolean false`. If I then add the integer casting and rerun the above code, it outputs `boolean true` like it is supposed to.

I'm new to GitHub, so if you need any additional information or have any other suggestions on the best way to fix this issue, let me know.