Eloquent is an Active Record implementation, not a Data Mapper implementation. What that means is it will not do the joins for you. If you want to do that sort of stuff without having to write the joins yourself then use something like Doctrine 2.
If you dont mind to write the joins by yourself try something like
/**
* Sort model by parameters given in the URL
* i.e: ?sortby=name&sortdir=desc
*
* @param Illuminate\Database\Eloquent\Builder
* @return Illuminate\Database\Eloquent\Builder
*/
public function scopeOrderByUrl($query)
{
$column = Input::get('sortby');
$direction = (Input::get('sortdir') == 'desc') ? 'desc' : 'asc';
return $query
->select($this->getTable().'.*') // Avoid 'ambiguous column name' for paginate() method
->leftJoin($table, $column, '=', "$table.id") // Include related table
->orderBy("$table.$relatedColumn", $direction); // Sort by related column
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community