php - Laravel query builder with limit of where-functions
Get the solution ↓↓↓Solution:
You can use:
$query = User::where(function($query) {
$query->where('type', '=', 'Apple')
->orWhere('type', '=', 'Coconut');
)}->get();
This will get both coconut and apples..
Answer
Solution:
If you're looking to limit the results toApple
s orCoconut
s, you should use the correct->orWhere()
statement, instead of another->where()
. By default, chaining->where()
clauses will result inWHERE ... AND ... AND ...
. Changing your$query
to:
$query = User::where('type', '=', 'Apple')->orWhere('type', '=', 'Coconut')->get();
will result in the queryWHERE ... OR ...
, and limit your results toApple
s orCoconut
s.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: property [id] does not exist on this collection instance.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.