I have three models
Invoice
Studio
R_studio_pay
Relationships are as follows
studio hasMany Invoice
studio hasOne R_studio_pay
I need to get invoices->where('recurring', 'single')->get() if a column is_r is 1 in R_studio_pay else i don't want the where clause.
I tried using whereHas studio-> wherehas R_studio_pay but conditional where cannot be done.
$invoices = invoice::with('studio')->whereHas('studio', function($query) {
$query->whereHas('r_studio_pay', function($query) {
$query->where('is_r', 1);
});
})->where('recurring', 'single')
But couldn't apply conditional where.