yafeearun
6 months ago

how to get accounts which are have projects

Posted 6 months ago by yafeearun

Hi

i have tried to get back the accounts which are have the projects,but accounts doesn't have the project id but invoice have account id and project id. so i mentioned the relationship like

public function invoices()
{
        return $this->hasManyThrough('App\Models\Invoice', 'App\Models\Project')->latest('due_date');
}

and i know we can get the result if we know the account id like

$account = 123
$result->with(['invoices.project'=> function($q) use ($account){
            $q->where('account_id',$account);
    }])->get()->toArray();

but i need to fetch only accounts which are have projects. let me help to short out it...

Please sign in or create an account to participate in this conversation.