-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort by #24
Comments
That is how Nova handles associatable resources also |
Hello there, To follow dillingham#24, sorting by display isn't necessary since the user already provided the sort in nova Gautier
Bummer this was closed, I was looking for something similar, but since this package doesn't offer any sort of configuration had to add a global scope like this: protected static function boot()
{
parent::boot();
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('sort_order', 'asc');
});
} Certainly not ideal, because I dislike using global scopes like this. |
I'm afraid I'm probably misunderstanding something (or many things!), but here is how I'm seeing things:
Please correct me if I'm wrong. Thanks. |
I just added a simple Pull Request (#89) to allow for sorting. I just noticed in currently only supports ASC sort order, but that can probably easily be changed.... I'd just like to get some comments from @dillingham & others to see if I'm on the right track. |
@YasamDevelopment After digging into the code I discovered it can be done by adding this method to the resource class: public static function relatableApplications(NovaRequest $request, $query)
{
return $query->orderBy('name');
} Where public function fields(Request $request)
{
return [
// ...
AttachMany::make('Select Applications', 'applications', Application::class),
];
} If that method doesn't exist, it falls back to HTH |
@davejamesmiller , Thank you! Wow, how did I ever miss that documentation?! (I guess it didn't help that Nova documented it in their Authorization section - https://nova.laravel.com/docs/3.0/resources/authorization.html#relatable-filtering - which I hadn't paid much attention to since I was not concerned with Authorization within Nova.) But anyhow, this is great information to know - thank you again for sharing with me (and others who might also come here searching). I implemented it in my code, and it works beautifully. |
Haha, I missed the documentation too - was looking for "sort" or "order by"! |
Hi @dillingham
Thanks for the package, really like it so far.
But I encountered a problem:
I need the items in a specific order. Is that possible?
It seems you force the order to be alphabetically.
The text was updated successfully, but these errors were encountered: