Download the PHP package msouto/nova-sortable without Composer
On this page you can find all versions of the php package msouto/nova-sortable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nova-sortable
Features
- Drag & drop reorder (on either Index view or HasMany view)
- BelongsTo/MorphsTo reorder support w/ pivot tables
- Move to start and end arrows (makes item first/last)
- Everything from eloquent-sortable
- Localization
Screenshots
Installation
Install the package in a Laravel Nova project via Composer:
Usage
Create migration
Add an order field to the model using Laravel migrations:
Implement eloquent-sortable
Implement the Spatie's eloquent-sortable
interface and apply the trait:
When the model does not have a sortable configuration, the default eloquent-sortable configuration will be used.
Apply HasSortableRows to Nova resource
Apply HasSortableRows
trait from this package on the Resource:
NB! This overrides the indexQuery()
method.
Disallowing sorting on a per-request/resource basis
You can disable sorting on a per-request or per-resource basis by overriding the canSort()
on the Resource method like so:
Custom sortable options
Nova sorting order
To sort your resource in a different order in Nova, you can set the nova_order_by
flag to DESC
(ASC
by default) in the $sortable
array.
Ignoring policies
If you have a resource that has authorizedToUpdate
false, but you want the user to still be able to sort it, you can use the ignore_policies
flag like so:
Sorting on HasMany relationship
NB! The resource can only be sorted on either the Index view or the HasMany list view, but not both!
Sorting on HasMany is simple. Add 'sort_on_has_many' => true
to the $sortable
array on the model. Like so:
The sort on has many configuration can be apply in a per model basis or it can be added in the eloquent-sortable configuration for all the models.
Sorting on ManyToMany relationships
Sorting on BelongsToMany and MorphToMany relationships is available, but requires special steps.
See the documentation here: Sorting ManyToMany relationships (w/ pivot table).
Localization
The translation file(s) can be published by using the following publish command:
You can add your translations to resources/lang/vendor/nova-sortable/
by creating a new translations file with the locale name (ie et.json
) and copying the JSON from the existing en.json
.
Credits
License
Nova Sortable is open-sourced software licensed under the MIT license.
All versions of nova-sortable with dependencies
spatie/eloquent-sortable Version ^3.10.0|^4.0
laravel/nova Version ^3.0
optimistdigital/nova-translations-loader Version ^2.0.0