replace symbol for space

0

I need to replace the + sign with % 20

Example: Are + Paulo by Are% 20Paulo

search is in Laravel with knockout

    
asked by anonymous 27.01.2018 / 21:32

1 answer

0

DBsearch

public function byQuery($query)
    {
        return \Title::whereTitleLike(preg_replace("/[ -:\'\"]/i", '%', $query))->orderBy('created_at','desc')->get();
    }
}

blade

controller

original

{
            $encoded = $query;
        }
        else
        {
            $encoded = urlencode($query);
        }

modified

public function byQuery()
    {       
        $query = (string) Input::get('genre');

        if ( ! $query || Str::length($query) <= 1)
            return View::make('Search.Results')->withTerm('');

        //don't encode the query if we will search our db as that will
        //cause problems
        if ( is_a($this->search, 'Lib\Services\Search\DbSearch') )
        {
            $encoded = urldecode($query);
        }
        else
        {
            $encoded = urldecode($query);
        }

        if ( ! Cache::tags('search')->has($this->provider.'search'.$encoded))
        {
            $results = $this->search->byQuery($encoded);
            Cache::tags('search')->put($this->provider.'search'.$encoded, $results, 8640);
        }
        else
        {
            $results = Cache::tags('search')->get($this->provider.'search'.$encoded);   
        }

        return View::make('Search.Results')->withData($results)->withTerm(e($query));
    }
    
28.01.2018 / 10:51