Answer the question
In order to leave comments, you need to log in
How to build a query correctly?
I need to find a model1 that has a model2, where model2 has a number greater than the number of model 1 by 10
, I try like this:
Model1::whereHas('model2', function ($query){
$query->where('number', '>', $model1->number+10)
});
Answer the question
In order to leave comments, you need to log in
You need to do it through mysql because at the query level you don't have $model1
something like this
Model1::whereHas('model2', function ($query){
$query->whereRaw('number', '>', 'model1.number+10')
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question