Tucker-Eric / EloquentFilter

An Eloquent Way To Filter Laravel Models And Their Relationships
http://tucker-eric.github.io/EloquentFilter
MIT License
1.72k stars 120 forks source link

sorted by table with relation #153

Closed Osaidx closed 3 years ago

Osaidx commented 3 years ago

Hi Tucker-Eric it's awesome package thank you ! i'm trying to order finally result by column name like that

 public function examins($ss = true)
    {
        return $this->whereHas('examinations', function($query) 
        {
            return $query->orderBy('price', 'desc');
        });

    }

but order by price did not apply on query
please your help

Tucker-Eric commented 3 years ago

You want to join the related table to order by one of it's columns.

Very rough example would be:

public function examins($ss = true)
{
    return $this->leftJoin('examinations', 'examinations.LOCAL_COL', '=', $this_table_and_col_reference)
        ->orderBy('examinations.price', 'desc');
}