Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Check if the user has EVERY permission given in the array , array must be given
- * @return bool
- */
- public static function hasAllPermissions($givenPerms){
- $user = Auth::user();
- $user->role->perm;
- $valid = true;
- if (is_array($givenPerms)) {
- $user_perms = array();
- foreach ($user->role->perm as $perm) {
- $user_perms[] = $perm->name;
- }
- if(in_array('admin', $user_perms)){
- return true;
- }
- foreach ($givenPerms as $singlePerm){
- if (!in_array($singlePerm, $user_perms)) {
- $valid = false;
- }
- }
- }else{
- $valid = false;
- dd('No array given in hasALLPermissions');
- }
- if($valid){
- return true;
- }
- return false;
- }
- /**
- * * @param array givenperms
- * Check if the user has ANY of the permission given, array must be given
- * if one is found we return true
- * @return bool
- */
- public static function hasAnyPermission($givenPerms){
- $user = Auth::user();
- $user->role->perm;
- if (is_array($givenPerms)) {
- $user_perms = array();
- foreach ($user->role->perm as $perm) {
- $user_perms[] = $perm->name;
- }
- if(in_array('admin', $user_perms)){
- return true;
- }
- foreach ($givenPerms as $singlePerm){
- if (in_array($singlePerm, $user_perms)) {
- return true;
- }
- }
- }else{
- dd('No array given in hasAnyPermission');
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement