I am working on a Laravel field that has a Listing
model and this model has many Price
models associated. The Price
model has a date
date field. I want to query the listings that have price entries daily for the given range, but I cannot wrap my mind around how I can achieve this with Eloquent, the only way I could do it is pulling the listings that have some prices at all and having PHP loop through the results, but that is ineffective and resource consuming. I would like to do it with SQL only. Can anybody point me towards a solution?
$query->where(function ($query) use ($startDate, $endDate) {
$query->whereHas('prices', function ($query) use ($startDate, $endDate) {
});
});