src/Traits/CrudModels.php
private static function filterWithQuery($registros, $config, $datos = [], $orOperation = "_or", $queryStr = "_q", $attriStr = "_a", $aByAStr = "_aByA") {
        if (count($datos) == 0) {
            $datos = request()->all();
        }
        //echo "<pre>" . print_r($datos, true) . "</pre>";
        if (!is_bool($orOperation)) {
            if (isset($datos[$orOperation])) {
                $orOperation = !($datos[$orOperation] === 'false');
            } else {
                $orOperation = true;
            }
        }
        if (isset($datos[$queryStr])) {
            $query = $datos[$queryStr];
            if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($query)) {
                $query = json_decode($query, true);
            } elseif (stripos($query, "|")) {
                $query = explode("|", $query);
            }
            if (isset($datos[$attriStr])) {
                $attri = $datos[$attriStr];
                if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($attri)) {
                    $attri = json_decode($attri, true);
                } elseif (stripos($attri, "|")) {
                    $attri = explode("|", $attri);
                }
            } else {
                $attri = $config['nombre'];
            }
            $fbf = isset($datos[$aByAStr]);
            $registros = $registros->filter(function($registro) use($query, $attri, $fbf, $orOperation) {
                return \Sirgrimorum\CrudGenerator\CrudGenerator::evaluateFilter($registro, $query, $attri, $orOperation, $fbf);
            });
        }
        return $registros;
    }
private static function filterWithQuery($registros, $config, $datos = [], $orOperation = "_or", $queryStr = "_q", $attriStr = "_a", $aByAStr = "_aByA") {
        if (count($datos) == 0) {
            $datos = request()->all();
        }
        //echo "<pre>" . print_r($datos, true) . "</pre>";
        if (!is_bool($orOperation)) {
            if (isset($datos[$orOperation])) {
                $orOperation = !($datos[$orOperation] === 'false');
            } else {
                $orOperation = true;
            }
        }
        if (isset($datos[$queryStr])) {
            $query = $datos[$queryStr];
            if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($query)) {
                $query = json_decode($query, true);
            } elseif (stripos($query, "|")) {
                $query = explode("|", $query);
            }
            if (isset($datos[$attriStr])) {
                $attri = $datos[$attriStr];
                if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($attri)) {
                    $attri = json_decode($attri, true);
                } elseif (stripos($attri, "|")) {
                    $attri = explode("|", $attri);
                }
            } else {
                $attri = $config['nombre'];
            }
            $fbf = isset($datos[$aByAStr]);
            $registros = $registros->filter(function($registro) use($query, $attri, $fbf, $orOperation) {
                return \Sirgrimorum\CrudGenerator\CrudGenerator::evaluateFilter($registro, $query, $attri, $orOperation, $fbf);
            });
        }
        return $registros;
    }
private static function filterWithQuery ( $ registros , $ config , $ datos = [ ] , $ orOperation = "_or" , $ queryStr = "_q" , $ attriStr = "_a" , $ aByAStr = "_aByA" ) { if ( count ( $ datos ) == 0 ) { $ datos = request ( ) -> all ( ) ; } //echo "<pre>" . print_r($datos, true) . "</pre>"; if ( ! is_bool ( $ orOperation ) ) { if ( isset ( $ datos [ $ orOperation ] ) ) { $ orOperation = ! ( $ datos [ $ orOperation ] === 'false' ) ; } else { $ orOperation = true ; } } if ( isset ( $ datos [ $ queryStr ] ) ) { $ query = $ datos [ $ queryStr ] ; if ( \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: isJsonString ( $ query ) ) { $ query = json_decode ( $ query , true ) ; } elseif ( stripos ( $ query , "|" ) ) { $ query = explode ( "|" , $ query ) ; } if ( isset ( $ datos [ $ attriStr ] ) ) { $ attri = $ datos [ $ attriStr ] ; if ( \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: isJsonString ( $ attri ) ) { $ attri = json_decode ( $ attri , true ) ; } elseif ( stripos ( $ attri , "|" ) ) { $ attri = explode ( "|" , $ attri ) ; } } else { $ attri = $ config [ 'nombre' ] ; } $ fbf = isset ( $ datos [ $ aByAStr ] ) ; $ registros = $ registros -> filter ( function ( $ registro ) use ( $ query , $ attri , $ fbf , $ orOperation ) { return \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: evaluateFilter ( $ registro , $ query , $ attri , $ orOperation , $ fbf ) ; } ) ; } return $ registros ; }
Filter a collection of object models using a query an attribute sets in an array.

The values in the $datos object must be strings, if using arrays, use json notation or separate the values with an |.

If not attribute is given, it will compare against the $config('nombre'] attribute

If $query contains "*%" it will erase them and evaluate if $query is contained in the attribute value.
Not aplicable for function or methods returns

@param object $registros Collection of elocuent model objects
@param array $config Configuration array for the Model
@param boolean|string $orOperation Optional boolean or the key of the or value in $datos. if True: use or operation (just one query must be true), false will use and operation (all the querys must be true).
@param array $datos Optional the data. if empty, it will get the current request data.
@param string $queryStr Optional the key of the query in $datos
@param string $attriStr Optional the key of the attributes in $datos
@param string $aByAStr Optional the key of the value indicating if the $query and $attribute must be evaluated one by one (ej: $query[0] vs $attribute[0] AND $query[1] vs $attribute[1], ...)
@return array Collection filtered
Filter a collection of object models using a query an attribute sets in an array .