1
I need to sort the results by column distance
relationship between order and address by paging the results.
Order:
public function address()
{
return $this->morphOne(Address::class, 'addressable');
}
Address:
public function addressable()
{
return $this->morphTo();
}
I tried the way down but didn’t order:
$orders = Order::with(['address' => function ($query) {
$query->orderBy('distance', 'asc');
}])->paginate(15)
Tries
$query->orderBy('address.distance', 'asc');
– Kayo Bruno
Unknown column 'address.Distance'
– Marcelo