src/Maxfactor.php
public function urlWithQuerystring(string $url, string $allowedParameters = null) : string
    {
        if (!$allowedParameters) {
            return $url;
        }

        $allowedParameters = str_start($allowedParameters, '/');
        $allowedParameters = str_finish($allowedParameters, '/');

        $currentQuery = collect(request()->query())->filter(function ($value, $parameter) use ($allowedParameters) {
            return preg_match($allowedParameters, sprintf('%s=%s', $parameter, $value));
        });

        if (!$newQuery = http_build_query($currentQuery->all())) {
            return $url;
        };

        return sprintf('%s?%s', $url, $newQuery);
    }
public function urlWithQuerystring(string $url, string $allowedParameters = null) : string
    {
        if (!$allowedParameters) {
            return $url;
        }

        $allowedParameters = str_start($allowedParameters, '/');
        $allowedParameters = str_finish($allowedParameters, '/');

        $currentQuery = collect(request()->query())->filter(function ($value, $parameter) use ($allowedParameters) {
            return preg_match($allowedParameters, sprintf('%s=%s', $parameter, $value));
        });

        if (!$newQuery = http_build_query($currentQuery->all())) {
            return $url;
        };

        return sprintf('%s?%s', $url, $newQuery);
    }
public function urlWithQuerystring ( string $ url , string $ allowedParameters = null ) : string { if ( ! $ allowedParameters ) { return $ url ; } $ allowedParameters = str_start ( $ allowedParameters , '/' ) ; $ allowedParameters = str_finish ( $ allowedParameters , '/' ) ; $ currentQuery = collect ( request ( ) -> query ( ) ) -> filter ( function ( $ value , $ parameter ) use ( $ allowedParameters ) { return preg_match ( $ allowedParameters , sprintf ( '%s=%s' , $ parameter , $ value ) ) ; } ) ; if ( ! $ newQuery = http_build_query ( $ currentQuery -> all ( ) ) ) { return $ url ; } ; return sprintf ( '%s?%s' , $ url , $ newQuery ) ; }
Returns a url with query string where the final querystring is a filtered
version of the current querystring.

@param string $url
@param string $allowedParameters  Accepts a string or regular expression
@return string
Returns a url with query string where the final querystring is a filtered version of the current querystring .