Created
August 2, 2018 22:01
-
-
Save zaratedev/8812dcaf5b7ad8cbfec4e9357eee0f97 to your computer and use it in GitHub Desktop.
Check Role Trait for PHP Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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