Skip to content

4.5.0

Compare
Choose a tag to compare
@binaryk binaryk released this 21 Dec 09:28
· 94 commits to 4.x since this release
fe628f5

Added

  • Sorting by belongsTo relationship:

Sometimes you may need to sort by a belongsTo relationship. This become a breeze with Restify. Firstly you have to
instruct your sort to use a relationship:

// PostRepository
use Binaryk\LaravelRestify\Fields\BelongsTo;
use Binaryk\LaravelRestify\Filters\SortableFilter;

public static function sorts(): array
{
    return [
        'users.name' => SortableFilter::make()
            ->setColumn('users.name')
            ->usingBelongsTo(
                BelongsTo::make('user', 'user', UserRepository::class),
        )
    ];
}

Make sure that the column is fully qualified (include the table name).

The request could look like:

GET: /api/restify/posts?sort=-users.name

This will return all posts, sorted descending by users name.