theUnforgiven
4 years ago

'%' in search term rather than +

Posted 4 years ago by theUnforgiven

How can I get this to happen

search?term=php%for%beginners

Rather than

search?term=php+for+beginners

Heres the search code in my controller:

public function search()
    {
        $this->page_path = 'search';

        $searchTerms = explode(' ', Input::get('term'));

        if (empty($searchTerms)) {
            return Redirect::back();
        }

        $query = Books::query();
        foreach ($searchTerms as $t) {
            $query->where('main_title', 'LIKE', '%'.$t . '%');
            $query->orWhere('sur_1', 'LIKE', $t . '%');
            $query->orWhere('fore_1', 'LIKE', $t . '%');
            $query->orWhere('sur_2', 'LIKE', $t . '%');
            $query->orWhere('fore_2', 'LIKE', $t . '%');
            $query->orWhere('sur_3', 'LIKE', $t . '%');
            $query->orWhere('fore_3', 'LIKE','%'. $t . '%');
        }

        $books = $query->paginate(10);
        $books->appends(['term' => Input::get('term')]);
        $terms           = Input::get('term');

        return View::make('site.results', compact('books', 'terms'));
    }

Please sign in or create an account to participate in this conversation.