Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role helper for user model #6

Merged
merged 2 commits into from
Jan 9, 2014

Conversation

ahmadshah
Copy link
Contributor

Add role checker for user model.

$user = User::find(1);

$user->is('foo'); //check if user has the specified role
$user->isAny(['foo', 'bar']); //check if user has at least one of the roles

$user->isNot('foo'); //check if user does not has the specified role
$user->isNotAny(['foo', 'bar']); //check if user does not has at lease one of the roles

Signed-off-by: ahmadshah ahmadshahhafizan@gmail.com

Signed-off-by: ahmadshah <ahmadshahhafizan@gmail.com>
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 9851c20 on ahmadshah:feature/user-model-helper into 77ea1d3 on orchestral:2.1.

*/
public function isAny(array $roles)
{
$userRoles = $this->roles();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would work since $this->roles() would return the relationship class, and not the result, why not abstract it out to another method.

protected function resolveRolesNameAsList()
{
    return $this->roles()->list('name');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup apparently it does not work since it is not returning array. Will update the PR

@ghost ghost assigned crynobone Jan 9, 2014
Signed-off-by: ahmadshah <ahmadshahhafizan@gmail.com>
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 9f93772 on ahmadshah:feature/user-model-helper into 77ea1d3 on orchestral:2.1.

crynobone added a commit that referenced this pull request Jan 9, 2014
@crynobone crynobone merged commit 851f38f into orchestral:2.1 Jan 9, 2014
@crynobone
Copy link
Member

👍 thanks

@ahmadshah ahmadshah deleted the feature/user-model-helper branch January 9, 2014 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants