This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

phplee
phplee

Hi

I have a car table that has a relationship with a contract table for leasing cars. I want to list the cars but order then by the cheapest contract which is stored in the contract table field 'monthly_rental' . The monlthy_rental field in the contract table can also be NULL for 'Call For Price' etc. I've managed to order the contract table by NULL last but can't seem to find how i actually order the cars by the cheapest monthly_rental in the contracts table. hers what i have so far.

 $vehicles = Vehicle::with(['contracts' => function($query){
        $query->orderByRaw('monthly_rental IS NULL, monthly_rental ASC');
    }]);

Adding something like this

$vehicles->orderBy(contracts.monthly_rental,  'ASC')

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.