src/Traits/CommandModel.php
public function scopeWithRequestSort($query)
    {
        if (($sorts = \Request::get('sort', false))) {
            // We list all sorting options
            $sorts = explode(',', $sorts);

            foreach ($sorts as $sort) {
                $order = 'asc';

                // If the first character is a dash (-), then the sort order is reversed
                if (substr($sort, 0, 1) === '-') {
                    $order = 'desc';

                    // We need to remove the dash from the sort because it is used in the orderBy method.
                    $sort = substr($sort, 1, strlen($sort));
                }

                $query->orderBy($sort, $order);
            }
        }

        return $query;
    }
public function scopeWithRequestSort($query)
    {
        if (($sorts = \Request::get('sort', false))) {
            // We list all sorting options
            $sorts = explode(',', $sorts);

            foreach ($sorts as $sort) {
                $order = 'asc';

                // If the first character is a dash (-), then the sort order is reversed
                if (substr($sort, 0, 1) === '-') {
                    $order = 'desc';

                    // We need to remove the dash from the sort because it is used in the orderBy method.
                    $sort = substr($sort, 1, strlen($sort));
                }

                $query->orderBy($sort, $order);
            }
        }

        return $query;
    }
This scope automatically sorts a query depending on the request.
A request looks like this:
- Sort by [column ASC]:                     ?sort=column
- Sort by [column DESC]:                    ?sort=-column
- Sort by [column1 ASC] and [column2 DESC]: ?sort=column1,-column2

@param $query
@return mixed