Support the ongoing development of Laravel.io →
Database Eloquent

Hello, I am trying to query two hasMany relationships, if an id is in the url I would also like to pull out the data just for that record. Here is what I have so far, however, I am not getting anything returned:

$payments= App::make('mainPayments');

if($id != 0){
    $payments= $payments->where('mainPaymentsID','=',$id);
}

$payments->whereHas('otherPayments',function($query) use ($term)
{
    $query->whereHas('user',function($query) use ($term)
    {
        if($term != ''){
            $query->where('userName', 'LIKE', "%".$term."%");
        }
    });
}
)->paginate($this->pageSize);

Can anyone please help?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mharrisweb mharrisweb Joined 23 Jul 2014

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.

© 2025 Laravel.io - All rights reserved.