src/Traits/CrudModels.php
public static function buildConditionalArray(array $config, string $action = "-") {
        if ($action == "") {
            $action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
        }
        $condiciones = [];
        $validadores = [];
        $tabla = $config['tabla'];
        foreach ($config['campos'] as $campo => $datos) {
            if (\Sirgrimorum\CrudGenerator\CrudGenerator::inside_array($datos, "hide", $action) === false) {
                if (isset($datos['conditional'])) {
                    if (is_array($datos['conditional'])) {
                        $validadores["{$tabla}_{$campo}"] = [];
                        foreach ($datos['conditional'] as $conCampo => $conValor) {
                            if (!isset($condiciones["{$tabla}_{$conCampo}"])) {
                                $condiciones["{$tabla}_{$conCampo}"] = [];
                            }
                            $condiciones["{$tabla}_{$conCampo}"][] = "{$tabla}_{$campo}";
                            $validadores["{$tabla}_{$campo}"]["{$tabla}_{$conCampo}"] = $conValor;
                        }
                    }
                }
            }
        }
        return [$condiciones, $validadores];
    }
public static function buildConditionalArray(array $config, string $action = "-") {
        if ($action == "") {
            $action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
        }
        $condiciones = [];
        $validadores = [];
        $tabla = $config['tabla'];
        foreach ($config['campos'] as $campo => $datos) {
            if (\Sirgrimorum\CrudGenerator\CrudGenerator::inside_array($datos, "hide", $action) === false) {
                if (isset($datos['conditional'])) {
                    if (is_array($datos['conditional'])) {
                        $validadores["{$tabla}_{$campo}"] = [];
                        foreach ($datos['conditional'] as $conCampo => $conValor) {
                            if (!isset($condiciones["{$tabla}_{$conCampo}"])) {
                                $condiciones["{$tabla}_{$conCampo}"] = [];
                            }
                            $condiciones["{$tabla}_{$conCampo}"][] = "{$tabla}_{$campo}";
                            $validadores["{$tabla}_{$campo}"]["{$tabla}_{$conCampo}"] = $conValor;
                        }
                    }
                }
            }
        }
        return [$condiciones, $validadores];
    }
public static function buildConditionalArray ( array $ config , string $ action = "-" ) { if ( $ action == "" ) { $ action = substr ( request ( ) -> route ( ) -> getName ( ) , stripos ( request ( ) -> route ( ) -> getName ( ) , "::" ) + 2 ) ; } $ condiciones = [ ] ; $ validadores = [ ] ; $ tabla = $ config [ 'tabla' ] ; foreach ( $ config [ 'campos' ] as $ campo => $ datos ) { if ( \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: inside_array ( $ datos , "hide" , $ action ) === false ) { if ( isset ( $ datos [ 'conditional' ] ) ) { if ( is_array ( $ datos [ 'conditional' ] ) ) { $ validadores [ "{$tabla}_{$campo}" ] = [ ] ; foreach ( $ datos [ 'conditional' ] as $ conCampo => $ conValor ) { if ( ! isset ( $ condiciones [ "{$tabla}_{$conCampo}" ] ) ) { $ condiciones [ "{$tabla}_{$conCampo}" ] = [ ] ; } $ condiciones [ "{$tabla}_{$conCampo}" ] [ ] = "{$tabla}_{$campo}" ; $ validadores [ "{$tabla}_{$campo}" ] [ "{$tabla}_{$conCampo}" ] = $ conValor ; } } } } } return [ $ condiciones , $ validadores ] ; }
Build the array for conditional fields using a configuration array
@param array $config The ocnfiguration array
@param string $action Optional the action (create, edit, etc) where the conditionals are needed
Build the array for conditional fields using a configuration array