Use whereHas and whereDoesntHave https://laravel.com/docs/7.x/eloquent-relationships#querying-relationship-existence Please mark this thread as solved it that works for you
@Hrvoje Jukic, my laravel version is 5.1 and can you explain little bit how will it return 0 if there is no data in a month!
WhereHas will allow you to fetch only the records having/missing payments.
If you don't want it in the where section, but in the select you should use withCount.
Hrvoje Jukic. It did not meet my requirement, it returning the same result as i am getting.. i will explain little bit more to you:
Result I am getting from that query:
{ payment_amount: 5000, month:1 }, { payment_amount: 4500, month:3 }, { payment_amount: 5500, month:5 }
The result i am expecting:
{ payment_amount: 5000, month:1 }, { payment_amount: 0, month:2 }, { payment_amount: 4500, month:3 }, { payment_amount: 0, month:4 }, { payment_amount: 5500, month:5 }
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community