Support the ongoing development of Laravel.io →
posted 4 years ago
Laravel
Last updated 2 years ago.
0

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

0

@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!

0

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.

0

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 }

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.