Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for bindings order when using where clause #127

Merged
merged 2 commits into from Dec 16, 2016
Merged

fix for bindings order when using where clause #127

merged 2 commits into from Dec 16, 2016

Conversation

n1crack
Copy link
Contributor

@n1crack n1crack commented Dec 10, 2016

The bindings order were wrong. The following code includes published scope which is $query->where('published_at', '<=', Carbon::now()); ..

$articles = Article::with('category')->published()->search($request->get('q'))->paginate(10);

params are:
0 2016-12-10 10:56:21
1 2016-12-10 10:56:21
2 test
3 test%
4 %test%
5 test
6 test%
7 %test%

which is wrong.
Correct Params should have been with this order :

0	test
1	test%
2	%test%
3	test
4	test%
5	%test%
6	2016-12-10 10:56:21
7	2016-12-10 10:56:21

My sql was like : (date and query params were at wrong places.)
select count() as aggregate from (select articles., max((case when LOWER(articles.title) LIKE '2016-12-10 10:56:21'' then 300 else 0 end) ..... bla bla bla.... having relevance > 7.50 order by relevance desc) as articles where published_at <= '%test%'

So made the changes. That fixed my issue for me . I am not sure if it breaks anything. So someone else should test it.

I am using laravel 5.3

have a good day.

fix for bindings order when using where clause
@nicolaslopezj
Copy link
Owner

Nice! Can someone confirm this is working for everyone?

@diszad
Copy link

diszad commented Dec 14, 2016

@nicolaslopezj This works for me.

@nicolaslopezj nicolaslopezj merged commit 1351b1b into nicolaslopezj:master Dec 16, 2016
@Ghaji
Copy link

Ghaji commented Apr 30, 2018

am trying to use the nicolaslopezj searchableTraits on Laravel 5.2.45 but getting this error "Call to undefined method Illuminate\Database\Query\Builder::search()" below is my controller can someone help

public function searchResult(Request $request){

	try {
        $v = validator()->make($request->all(), [
                'formsearch'       => 'required|min:3|max:50',
          ]);

        if( $v->fails() ) {

            return redirect()->back()->withInput()->withErrors($v);

        } else {

        	$users = User::search($request->get('formsearch'))->get();

        	return view('searchResult.search', compact('users'));
            
        }
    } catch(Exception $e) {
        return redirect()->back()->withMessage("An error occurred ".$e->getMessage());
    }

screen shot 2018-04-30 at 7 39 01 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants