Reputation: 311
I have a input form for search where user can post name or email to search items.but i don't know what should be the mysql eloquent query for this specific search.
I have tried
$email_or_name = Input::get('email_or_name');
$result = Marriage::where('name','LIKE','%'.$email_or_name.'%') or ->where('email','LIKE','%'.$email_or_name.'%')->get();
its gives the following exception
syntax error, unexpected '->' (T_OBJECT_OPERATOR)
then i have tried
$result = Marriage::where('name','LIKE','%'.$email_or_name.'%') or Marriage::where('email','LIKE','%'.$email_or_name.'%')->get();
if i put email address for search,it gives No result,
but if i put name,then it produce the desired results.So i suspect that the portion after the or
in the query is not working.If i am right , then what should be correct mysql eloquent query for this type of search,
Upvotes: 1
Views: 13562
Reputation: 152880
You can't just throw in an or
somewhere. However there is a method orWhere()
:
$result = Marriage::where('name','LIKE','%'.$email_or_name.'%')
->orWhere('email','LIKE','%'.$email_or_name.'%')
->get();
Upvotes: 10