Currently make some feature for seller able to download invoice based on month. So seller can choose which month that they want . Somehow my query doesnt work and keep taking wrong data . Anyone can help ?
$month = "3" ( STRING )
$seller_id = 1
// database
posts
id | title | user_id |
1 test 1
2 test2 2
deals
id | post_id | status |updated_at
1 1 Received 2020-03-01
2 1 Received 2020-03-01
3 2 Completed 2020-02-01
4 2 Dealing 2020-03-01
$deal = Deal::whereHas('post',function ($q) use ($seller_id){
$q->where('user_id',$seller_id);
})->whereMonth('updated_at',$month)->where('status','Received')->orWhere('status','Completed')->get();
expected result
$deal = 2 ( id => 1,2 )
current result = 3 ( id => 1,2,4 )