src/Traits/CrudModels.php
public static function checkPermission(array $config, $registro = 0, $action = "") {
        if ($action == "") {
            $action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
        }
        $resultado = true;
        $general = false;
        if (isset($config['permissions'])) {
            if (isset($config['permissions'][$action])) {
                $callback = $config['permissions'][$action];
            } elseif (isset($config['permissions']['default'])) {
                $callback = $config['permissions']['default'];
            } else {
                $general = true;
            }
        } else {
            $general = true;
        }
        if ($general) {
            $callback = config('sirgrimorum.crudgenerator.permission');
        }
        if (is_callable($callback)) {
            if ($registro > 0) {
                $objModelo = $config['modelo']::find($registro);
                $resultado = (bool) $callback($objModelo);
            } else {
                $resultado = (bool) $callback();
            }
        } else {
            $resultado = (bool) $callback;
        }

        return $resultado;
    }
public static function checkPermission(array $config, $registro = 0, $action = "") {
        if ($action == "") {
            $action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
        }
        $resultado = true;
        $general = false;
        if (isset($config['permissions'])) {
            if (isset($config['permissions'][$action])) {
                $callback = $config['permissions'][$action];
            } elseif (isset($config['permissions']['default'])) {
                $callback = $config['permissions']['default'];
            } else {
                $general = true;
            }
        } else {
            $general = true;
        }
        if ($general) {
            $callback = config('sirgrimorum.crudgenerator.permission');
        }
        if (is_callable($callback)) {
            if ($registro > 0) {
                $objModelo = $config['modelo']::find($registro);
                $resultado = (bool) $callback($objModelo);
            } else {
                $resultado = (bool) $callback();
            }
        } else {
            $resultado = (bool) $callback;
        }

        return $resultado;
    }
public static function checkPermission ( array $ config , $ registro = 0 , $ action = "" ) { if ( $ action == "" ) { $ action = substr ( request ( ) -> route ( ) -> getName ( ) , stripos ( request ( ) -> route ( ) -> getName ( ) , "::" ) + 2 ) ; } $ resultado = true ; $ general = false ; if ( isset ( $ config [ 'permissions' ] ) ) { if ( isset ( $ config [ 'permissions' ] [ $ action ] ) ) { $ callback = $ config [ 'permissions' ] [ $ action ] ; } elseif ( isset ( $ config [ 'permissions' ] [ 'default' ] ) ) { $ callback = $ config [ 'permissions' ] [ 'default' ] ; } else { $ general = true ; } } else { $ general = true ; } if ( $ general ) { $ callback = config ( 'sirgrimorum.crudgenerator.permission' ) ; } if ( is_callable ( $ callback ) ) { if ( $ registro > 0 ) { $ objModelo = $ config [ 'modelo' ] :: find ( $ registro ) ; $ resultado = ( bool ) $ callback ( $ objModelo ) ; } else { $ resultado = ( bool ) $ callback ( ) ; } } else { $ resultado = ( bool ) $ callback ; } return $ resultado ; }
Evaluate the "permissions" callbacks in the configuration array
@param array $config The configuration array
@param int $registro Optional The id of the registry
@param string $action Optional The actual action
@return boolean if the user has or not permission
Evaluate the permissions callbacks in the configuration array