1

I am having an issue where I am running a query with 3 where clauses using Laravel's Eloquent ORM. What I am trying to do is get the data WHERE condition A AND (condition B OR condition C). So currently I am running:

$searchData = e($data);
Model::where('user_id', 5)->where('title','LIKE', "%".$searchData."%")->orWhere('company_name','LIKE', "%".$searchData."%")->get();

Now the problem is that this is getting me 2 records when it should only have one, but its getting me two since the second record's company_name matches but the user_id does NOT. How can I make this enforce that the user_id be equal to the value I give it, but the 2 other where clauses be optional?

I have looked at several other SO posts and Laravel docs but can't seem to find what i'm looking for since I'm more than likely wording it incorrectly.

Thanks in advance, Cheers.

P.S. Running Eloquent for Laravel 5.1 outside of Laravel.

Geoherna
  • 3,523
  • 1
  • 24
  • 39
  • 1
    https://stackoverflow.com/questions/16995102/laravel-4-eloquent-where-with-or-and-or might answer your question – Pinke Helga Dec 09 '16 at 01:45
  • ^^^ That ended up getting me in the right direction. The solution was Eloquents parameter grouping: https://laravel.com/docs/5.1/queries#advanced-where-clauses – Geoherna Dec 09 '16 at 01:54

0 Answers0