Skip to content

Instantly share code, notes, and snippets.

@zaratedev
Created August 2, 2018 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaratedev/8812dcaf5b7ad8cbfec4e9357eee0f97 to your computer and use it in GitHub Desktop.
Save zaratedev/8812dcaf5b7ad8cbfec4e9357eee0f97 to your computer and use it in GitHub Desktop.
Check Role Trait for PHP Laravel
<?php
namespace App\Traits;
trait RoleCheck
{
/**
* function hasAnyRole.
*
* @param $roles
*
* @return bool
*/
public function hasAnyRole($roles)
{
if (!is_array($roles)) {
return $this->hasRole($roles);
}
foreach ($roles as $role) {
if ($this->hasRole($role)) {
return true;
}
}
return false;
}
/**
* function hasRole.
*
* @param $role
*
* @return bool
*/
public function hasRole($role)
{
return $this->role == $role;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment