Git Product home page Git Product logo

nova-sortable's Introduction

Nova Sortable

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to reorder models in a Nova resource's index view using drag & drop.

Uses Spatie's eloquent-sortable under the hood.

Requirements

  • php: >=8.0
  • laravel/nova: ^4.24.0

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

Sortable

Installation

Install the package in a Laravel Nova project via Composer:

# Install package
composer require outl1ne/nova-sortable

Usage

Create migration

Add an order field to the model using Laravel migrations:

// Add order column to the model
Schema::table('some_model', function (Blueprint $table) {
  $table->integer('sort_order');
});

// Set default sort order (just copy ID to sort order)
DB::statement('UPDATE some_model SET sort_order = id');

Implement eloquent-sortable

Implement the Spatie's eloquent-sortable interface and apply the trait:

use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class SomeModel extends Eloquent implements Sortable
{
  use SortableTrait;

  public $sortable = [
    'order_column_name' => 'sort_order',
    'sort_when_creating' => true,
  ];

  ...
}

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:

use Outl1ne\NovaSortable\Traits\HasSortableRows;

class MyResource extends Resource
{
  use HasSortableRows;

  ...
}

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:

public static function canSort(NovaRequest $request, $resource)
{
  // Do whatever here, ie:
  // return user()->isAdmin();
  // return $resource->id !== 5;
  return true;
}

NB! This requires you to disable caching (see below).

Disabling caching

If you want to disable caching due to using canSort or running tests, you can set sortableCacheEnabled to false on the resource that has the HasSortableRows trait. See the example below:

class Artist extends Resource
{
    use HasSortableRows;

    public static $sortableCacheEnabled = false;
}

Or if you want to temporarily disable sortability cache (for tests), you can call Resource::disableSortabilityCache() on the resource.

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.

class SomeModel extends Eloquent implements Sortable
{
  use SortableTrait;

  public $sortable = [
    'order_column_name' => 'sort_order',
    'sort_when_creating' => true,
    'nova_order_by' => 'DESC',
  ];

  ...
}

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:

class SomeModel extends Eloquent implements Sortable
{
  use SortableTrait;

  public $sortable = [
    'order_column_name' => 'sort_order',
    'sort_when_creating' => true,
    'ignore_policies' => true,
  ];

  ...
}

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:

public $sortable = [
  'order_column_name' => 'sort_order',
  'sort_when_creating' => true,
  'sort_on_has_many' => true,
];

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.

return [

    // Spatie sortable configuration

    /**
     * Add sort on has many in all the models.
     **/
    'sort_on_has_many' => true,
];

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:

php artisan vendor:publish --provider="Outl1ne\NovaSortable\ToolServiceProvider" --tag="translations"

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.

Other usecases

Using indexQuery

This package overwrites the indexQuery of the Resource and if you still want to use it, you can do it as follows:

use HasSortableRows {
    indexQuery as indexSortableQuery;
}

public static function indexQuery(NovaRequest $request, $query)
{
  // Do whatever with the query
  // ie $query->withCount(['children', 'descendants', 'modules']);
  return parent::indexQuery($request, static::indexSortableQuery($request, $query));
}

Credits

License

Nova Sortable is open-sourced software licensed under the MIT license.

nova-sortable's People

Contributors

abather avatar ackermann avatar andre4nap avatar angelsk avatar dependabot[bot] avatar everestmx avatar faridaghili avatar franciscokraefft avatar gerardnll avatar hugoheneault avatar jnewbon avatar jonerickson avatar kasparrosin avatar lisotton avatar ltkort avatar marispro avatar mennotempelaar avatar mertasan avatar mihai-stancu avatar mikaelpopowicz avatar mstaack avatar mynetx avatar naoray avatar newtongamajr avatar nrueckmann avatar pzmarzly avatar shaffe-fr avatar stefblokdijk avatar tarpsvo avatar trippo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nova-sortable's Issues

To sort on both Index view and HasMany list view.

I would need the resource to be sorted on both Index and HasMany list view.
Is there any rough ETA when this will be supported?

Here’s my schema table:

        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->unsignedInteger('parent_id')->index()->nullable();
            $table->unsignedInteger('sort_order');
            $table->timestamps();

            $table->foreign('parent_id')->references('id')->on('categories');
        });

And here’s my Category model:

class Category extends Model
{
    public function children()
    {
        return $this->hasMany(Category::class, 'parent_id', 'id');
    }
}


i.e. I have Categories and Subcategories with hasMany relationship. Both needs to be sorted.
Thank you.

updateOrder failed with group sorting

Hello,
I have a Post table, each post has a heading stored as string in a column (like news, podcasts, tests etc)
I've overridden buildSortQuery method in my Post model like so

 public function buildSortQuery()
    {
        return static::query()
        ->where('heading', $this->heading);
    }

It works very well on creation, displaying, move to end, move to top. But when I want to use the drag and drop feature the nova api give me a HTTP 400 resourceIds: invalid

I don't know if i'm using buildSortQuery well, I tried to look into the code, on L75 in OptimistDigital\NovaSortable\Http\Controllers\SortableController, if i remove the buildSortQuery from the query it works as intended.
Since we already getting the ids in the sorted scope (in my case, scoped by heading), do we really need to use the buildSortQuery on our model on this line ?

Thanks in advance πŸ˜„

Sorting Morphs

Any ideas on how to use sorting on morphedbymany relations?

Sort_order has duplicate sort values on update

Maybe i'm doing something wrong but i don't get it to work.

Package Version
PHP 7.4
laravel/nova 3.22.0
optimistdigital/nova-sortable 2.2.0

I've followed the "Installation" and "Usage" steps completely and added the sortable configuration to the Eloquent model:

public $sortable = [
  'order_column_name' => 'sort_order',
  'sort_when_creating' => true,
  'sort_on_has_many' => true,
];

In the Nova resource i've added the use HasSortableRows; trait. And i've update sort_order field in the table. So i'm starting with the following values in the table:
Schermafbeelding 2021-04-07 om 09 26 13

Now i'm moving the 3rd row to the 2nd row. It does as expected and i get the following result in the table:
Schermafbeelding 2021-04-07 om 09 28 01

Now I'm moving the 4th row to the 3rd row and it gets a sort_order value which already exists:
Schermafbeelding 2021-04-07 om 09 29 18

Am i missing something or is something going wrong in the fixSortOrder of the SortableController?

Sort on Pivot only

Hi there,

Not sure if this intended behaviour. But I want to sort only on relationships, so when it is on relationship/pivot table.

This below will return true even if it's not viaRelationship as the second property is set true in my model.

$sortable = $request->viaRelationship() ? $request->newResource()->resource->sortable['sort_on_pivot'] ?? false : true;

am I using it wrong or is this just how its meant to work.

I can fix this easily by over riding the serializeForIndex method though so no real action is needed if this intended behaviour.

On laravel 7 and Nova 3

Can't Install on Nova 3.14.0

Hi...

I'm trying to include this in a new project using Laravel 8.13.0 and Nova 3.14.0.

Whenever I try to install I'm getting the following:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - optimistdigital/nova-sortable[1.6.0, ..., 1.6.1] require laravel/nova ^2.0.11 || ^3.0 -> found laravel/nova[dev-main] but it does not match the constraint.
    - Root composer.json requires optimistdigital/nova-sortable ^1.6 -> satisfiable by optimistdigital/nova-sortable[1.6.0, 1.6.1].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

How can I get this installed into my project?

Thanks πŸ˜„

Change default order column name

Hello,
The default order column of this package is sort_order whereas spatie/eloquent-sortable uses order_column.
The same order column name would allow both packages to work without any configuration for simple use case.
As it would be a BC, would you be open to a PR to change the default order column name to "order_column"?
Thanks for your work,
Best,
Karel

only_show_on not working for one_to_many relationships

The pull request #36 has the only_sort_on, work for both many to many and one to many relationships

The commit 0429ee8 changed this para-dime to only allow the only_sort_on and dont_sort_on to work with many to many relationships and and disables the feature for one-to-many relationships.

Normally one-to-many relationship would only sort on the specific model they relate to but my use case is a nested one to many

Comic has-many Chapters
Comic has-many Pages
Chapter has-many Pages

Inverse

Page Belongs-to one Chapter
Page Belongs-to one Comic
Chapter Belongs-to one Comic

Comic <- Chapter <- Page

Chapters and pages can be sorted, Chapters should only be sorted when viewed under a comic, and pages should only be sorted when viewed under a chapter.

Adding the has sortableTrait to both chapters and pages, makes them sortable, however pages which should only be sortable under chapters is also sortable under comics, which breaks the ordering should the sorting be edited there.

The following lines
https://github.com/optimistdigital/nova-sortable/blob/58167609b9a35eba40e7a4f4f42b2eb50eda0354/src/Traits/HasSortableRows.php#L52-L70

Need to be placed outside the if statement on line
https://github.com/optimistdigital/nova-sortable/blob/58167609b9a35eba40e7a4f4f42b2eb50eda0354/src/Traits/HasSortableRows.php#L36

So that they also execute on all relationships not just many to many relationships.

Sorting on ManyToMany and Index view is possible

The documentation states that

NB! The resource can only be sorted on either the Index view or the HasMany list view, but not both!

That's not entirely true. If you name the column name on the PivotModel different than on your Model where you want to sort in the index view (e.g. PivotModel column name: sort_order, Model column name: order_column) and then add the following method to your Nova Resource

public static function getSortability(NovaRequest $request)
    {
        $response = HasSortableManyToManyRows::getSortability($request);

        if (!$request->viaManyToMany()) {
            return (object)[
                'model' => $response->model,
                'sortable' => $response->sortable,
                'sortOnBelongsTo' => false,
                'sortOnHasMany' => $response->sortOnHasMany,
            ];
        }

        return $response;
    }

Don't forget to change the order_column_name on your Model to order_column.

determineOrderColumnName is not callable as it's protected in the SortableTrait

The
http://my-laravel-server/nova-api/my-model?search=&filters=W10%3D&orderBy=&perPage=25&trashed=&page=1&relationshipType=
endpoint returns the following error:
message: "Call to undefined method App\MyModel::determineOrderColumnName()"

Unluckily, determineOrderColumnName is defined as protected in the trait, so it can't be called outside the object.
I had to do this dirty trick to make it work:

use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class MyModel extends Model implements Sortable
{
    use SortableTrait {
        determineOrderColumnName as traitDetermineOrderColumnName;
    }

    protected $fillable = ['name', 'order_number'];

    public $sortable = [
        'order_column_name' => 'order_number',
        'sort_when_creating' => true,
      ];

    /**
     * Dirty trick to make HasSortableRows work
     */
    public function determineOrderColumnName() {
        return $this->traitDetermineOrderColumnName();
    }
}

Is there a less dirty way to make it work?

"undefined" tooltip

Great stuff - the long-awaited sorting package!

Only issue I could find so far is the "undefined" tooltip:

scopes 2019-11-27 12-45-05

All ressources are sortable by default !

When adding sortable in a projet all Nova Resources are populated by default even without any trait implementation.

This was tested on multiple projects using Nova 3.19.1

Crash issue on withTrashed not fixed

@Tarpsvo b088d34 didn't fixed #48 and I guess is_callable is returning True on non SoftDeletes because of Eloquent's magic methods.

Just use method_exists instead of is_callable, I've tested this with and without SoftDeletes trait.

HasMany relationship issue solved

Hi,
Great package.
To support HasMany relationship, please update the "SortableController" code (line 24)

from

          if ($relationshipType === 'belongsToMany') {
                $resourceClass = Nova::resourceForKey($viaResource);
                if (empty($resourceClass)) return response()->json(['resourceName' => 'invalid'], 400);

                $modelClass = $resourceClass::$model;
                $model = $modelClass::find($viaResourceId);

                $pivotModels = $model->{$viaRelationship};
                if ($pivotModels->count() !== sizeof($resourceIds)) return response()->json(['resourceIds' => 'invalid'], 400);

                $pivotModel = $pivotModels->first()->pivot;
                $orderColumnName = !empty($pivotModel->sortable['order_column_name']) ? $pivotModel->sortable['order_column_name'] : 'sort_order';

                // Sort orderColumn values
                foreach ($pivotModels as $i => $model) {
                    $model->pivot->{$orderColumnName} = array_search($model->id, $resourceIds);
                    $model->pivot->save();
                }
            }

to

         if ($relationshipType === 'belongsToMany') {
                $resourceClass = Nova::resourceForKey($viaResource);
                if (empty($resourceClass)) return response()->json(['resourceName' => 'invalid'], 400);

                $modelClass = $resourceClass::$model;
                $model = $modelClass::find($viaResourceId);

                $pivotModels = $model->{$viaRelationship};
                if ($pivotModels->count() !== sizeof($resourceIds)) return response()->json(['resourceIds' => 'invalid'], 400);

                $pivotModel = $pivotModels->first()->pivot;
                $orderColumnName = !empty($pivotModel->sortable['order_column_name']) ? $pivotModel->sortable['order_column_name'] : 'sort_order';

                // Sort orderColumn values
                foreach ($pivotModels as $i => $model) {
                    $model->pivot->{$orderColumnName} = array_search($model->id, $resourceIds);
                    $model->pivot->save();
                }
            }
            elseif ($relationshipType === 'hasMany') {
                $resourceClass = Nova::resourceForKey($viaResource);
                if (empty($resourceClass)) return response()->json(['resourceName' => 'invalid'], 400);

                $modelClass = $resourceClass::$model;
                $model = $modelClass::find($viaResourceId);

                $pivotModels = $model->{$viaRelationship};
                if ($pivotModels->count() !== sizeof($resourceIds)) return response()->json(['resourceIds' => 'invalid'], 400);

                $pivotModel = $pivotModels->first();
                $orderColumnName = !empty($pivotModel->sortable['order_column_name']) ? $pivotModel->sortable['order_column_name'] : 'sort_order';

                // Sort orderColumn values
                $sortedOrder = $pivotModels->pluck($orderColumnName)->sort()->values();
                foreach ($resourceIds as $i => $id) {
                    $_model = $pivotModels->firstWhere('id', $id);
                    $_model->{$orderColumnName} = $sortedOrder[$i];
                    $_model->save();
                }
            }

Sortable on index AND has many

When putting sort_on_has_many on true. You can no longer sort on the index.

I would like to be able to sort on both index and has many.

When putting sort_on_has_many with the model on true, it disappears from the index.

Sortable should not show inside Lenses

I'm having a problem where I have a Lens inside a Resource with HasSortableRows trait, but inside the Lens even with a different order, it shows the order field where I can change the order. I already tried with canSort, but I can't find there if my request it's inside a Lens.

Thank you

Extend documentation hasMany

Hi,

While reading the docs, you are stating this:

Sorting on HasMany relationship
NB! The resource can only be sorted on either the Index view or the HasMany list view, but not both!

How do we choose to use the sortable trait on the the HasMany list view instead of the index view?

[Question] Sort ManyToMany

Does ManyToMany sorting allow to disable sorting on one of the Detail views?

I currently have a Place and a Dentist model which have a Many-to-Many relationship. I set it up so that Dentists can be sorted on the Places details view. On the Dentist details view the 'sort' icon is still showing up, even though it doesn't have any functionality. I thought adding $sortable = ['dont_sort_on' => App\Nova\Dentist::class'] should prevent the sort icon showing up on the Dentist detail view, but it doesn't seem to change anything.

Is there something I am missing?

Thanks for the help in advance!

400 error on update-order route

I am getting An error occurred while trying to reorder the resource. when I try to drag and drop reorder the rows. "Move to first" and "Move to end" work as expected.

When I check the console I have a Failed to load resource: the server responded with a status of 400 (Bad Request) On the update-order route.

Laravel : 6.18.15
Nova: 2.12
PHP: 7.3.1

The sort comp doesn't work with delete policy as false

I just added the package to my project and worked pretty good!
image

But then, I added a policy to my resource like:

    public function delete(User $user, ProductCollection $collection)
    {
        return false;
    }

And the comp is not available anymore (also the header columns are broken with the related row columns)
image

Can I bypass this issue with another option/setting?

Extra tr>td displayed on index view of resources with no actions

Originally reported as a Laravel Nova issue (laravel/nova-issues#3179) but I've narrowed it down to an issue with this package.

The first tbody>tr>td on the index view is reserved for checkboxes, but for resources that don't have any actions it shouldn't display any. It seems that this package's override of the ResourceTable component doesn't account for that and I end up with an extra column and everything is "shifted" over by a column. This happens even on resources which don't declare any sortable traits or columns.

Here's an example:

image

Disabling/removing this package solves the issue. Can you look into it please?

BelongsToMany Pivot Table Ordering

I've read the docs, and tried the example here, but I can't get ordering via a column on a Pivot table to work.

I have a tracks table, and an artists table, and they are linked with an artist_tracks table. I've added the sort_order column to the artist_tracks table, but no matter what I try, I can't get the draggable sorting behaviour to work in Nova (v.3.4.0) at all.

Is this possible? And if so, could you possibly tell me how to make this work please? πŸ˜„

Thanks

Overview orders on ID and not on sort_order

I'm trying to add sorting on a ManyToMany relationship between Playlist and Performance through a pivot table. I've followed the steps described in the documentation, but the relationship keeps ordering on ID, and not on sort_order. What am I missing here?

Here is my code:

app/Models/Playlist
Note: If I remove ->using(), ordering is done on sort_order like it should.

	/**
	 * Belongs to many relation with Performance.
	 *
	 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
	 */
	public function performances()
	{
		return $this->belongsToMany(Performance::class, 'playlist_performance')
			->orderBy('playlist_performance.sort_order')
			->using(PlaylistPerformance::class)
			->withTimestamps();
	}

app/Models/Performance
Note: This model is also sortable on another belongsTo relation, which works as expected.

        /**
	 * Sortable attributes used for the nova-sortable package.
	 *
	 * @var array
	 */
	public $sortable = [
		'order_column_name' => 'sort_order',
		'sort_when_creating' => true,
		'sort_on_has_many' => true,
	];

	/**
	 * Belongs to many relation with Playlist.
	 *
	 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
	 */
	public function playlists()
	{
		return $this->belongsToMany(Playlist::class, 'playlist_performance')
			->orderBy('playlist_performance.sort_order')
			->using(PlaylistPerformance::class)
			->withTimestamps();
	}

app/Models/PlaylistPerformance

class PlaylistPerformance extends Pivot implements Sortable
{
	use SortableTrait;

	public $primaryKey = 'id';
	public $incrementing = true;

	/**
	 * The table associated with the model.
	 *
	 * @var string
	 */
	protected $table = 'playlist_performance';

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'playlist_id',
		'performance_id',
		'sort_order'
	];

	/**
	 * The attributes that should be mutated to dates.
	 *
	 * @var array
	 */
	protected $dates = [
		'created_at',
		'updated_at'
	];

	public $sortable = [
		'order_column_name' => 'sort_order',
		'sort_when_creating' => true,
	];

	public function buildSortQuery()
	{
		return static::query()
			->where('playlist_id', $this->playlist_id);
	}
}

Here's what the table looks like in the DB:
Screenshot 2021-03-16 at 13 57 12

Confirm sort with button

Hello, I have a project where the client handles important information, so every changes that he makes it affects a lot of other users. He wants to be able to drag and drop items to sort them but I want if I can make it so the user has to click on a Confirm button before the sort changes on the database.

Unsortable rows

In my project, I have rows that I want them to be unsortable. Currently, I'm using something like this to prevent sorting:

// MyModel.php

protected static function boot()
{
    parent::boot();

    static::updating(function ($model) {
        $isSortable = /* some logic */;

        if ($model->isDirty('order_column') && !$isSortable) {
            throw new Exception('Model is not sortable!');
        }
    });
}

It works, but it displays 2 error toast on the page, one says "Model is not sortable!" (mine) and the other one says "An error occurred while trying to reorder the resource." (yours). It would be nice if somehow I can define for the package to when accept sorting and when do not.

Not able to getting it to work

Hi,

I've followed all the instructions and I'm not seeing the buttons to reorder the resources in the index page. I'm seeing the JS being loaded but nothing appears. I do not need to add order as a field right? I have the latest Nova and Laravel version.

Thanks.

Change in last commit (withTrashed) broke the code

After e0c83a2 when trying to sort rows by drag and drop, error occurs:
Call to undefined method App\Slide::withTrashed()

Log:

[2020-09-23 18:00:57] local.ERROR: Call to undefined method App\Slide::withTrashed() {"userId":1,"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method App\\Slide::withTrashed() at C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Traits\\ForwardsCalls.php:50)
[stacktrace]
#0 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Traits\\ForwardsCalls.php(36): Illuminate\\Database\\Eloquent\\Model::throwBadMethodCallException('withTrashed')
#1 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(1736): Illuminate\\Database\\Eloquent\\Model->forwardCallTo(Object(Illuminate\\Database\\Eloquent\\Builder), 'withTrashed', Array)
#2 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(1748): Illuminate\\Database\\Eloquent\\Model->__call('withTrashed', Array)
#3 C:\\Users\\farid\\www\\ahanghaa\\vendor\\optimistdigital\
ova-sortable\\src\\Http\\Controllers\\SortableController.php(76): Illuminate\\Database\\Eloquent\\Model::__callStatic('withTrashed', Array)
#4 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(48): OptimistDigital\\NovaSortable\\Http\\Controllers\\SortableController->updateOrder(Object(Laravel\\Nova\\Http\\Requests\\NovaRequest), 'slides')
#5 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(239): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(OptimistDigital\\NovaSortable\\Http\\Controllers\\SortableController), 'updateOrder')
#6 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(196): Illuminate\\Routing\\Route->runController()
#7 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(685): Illuminate\\Routing\\Route->run()
#8 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#9 C:\\Users\\farid\\www\\ahanghaa\
ova\\src\\Http\\Middleware\\Authorize.php(18): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#10 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Laravel\\Nova\\Http\\Middleware\\Authorize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#11 C:\\Users\\farid\\www\\ahanghaa\
ova\\src\\Http\\Middleware\\BootTools.php(20): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#12 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Laravel\\Nova\\Http\\Middleware\\BootTools->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#13 C:\\Users\\farid\\www\\ahanghaa\
ova\\src\\Http\\Middleware\\DispatchServingNovaEvent.php(20): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#14 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Laravel\\Nova\\Http\\Middleware\\DispatchServingNovaEvent->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#15 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#16 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#17 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\Middleware\\Authenticate.php(44): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 C:\\Users\\farid\\www\\ahanghaa\
ova\\src\\Http\\Middleware\\Authenticate.php(31): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#19 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Laravel\\Nova\\Http\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#20 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(77): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#21 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#22 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#23 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#24 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#25 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(62): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest(Object(Illuminate\\Http\\Request), Object(Illuminate\\Session\\Store), Object(Closure))
#26 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(687): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#33 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(662): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#34 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(628): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#35 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(617): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#36 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(165): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#37 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#38 C:\\Users\\farid\\www\\ahanghaa\
ova\\src\\Http\\Middleware\\ServeNova.php(26): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#39 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Laravel\\Nova\\Http\\Middleware\\ServeNova->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#40 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#41 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#42 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#43 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#44 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#45 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#46 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(63): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#47 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#48 C:\\Users\\farid\\www\\ahanghaa\\vendor\\fruitcake\\laravel-cors\\src\\HandleCors.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#49 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Fruitcake\\Cors\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#50 C:\\Users\\farid\\www\\ahanghaa\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#51 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#52 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#53 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(140): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#54 C:\\Users\\farid\\www\\ahanghaa\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(109): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#55 C:\\Users\\farid\\www\\ahanghaa\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#56 C:\\Users\\farid\\www\\ahanghaa\\server.php(21): require_once('C:\\\\Users\\\\farid\\\\...')
#57 {main}
"} 

Resource policies are ignored

nova-sortable currently ignores the policy rules for the associated resource:If a user does not have the right to change the resource the sortable function is still displayed in the UI and also executed although the user is not allowed to make any changes.

Global Search Not Working

Hi @Tarpsvo

I've just noticed that with the latest release, my global search isn't working, and I seem to be getting errors from the HasSortableRows trait.

My setup is detailed in #20 that we worked through over the last couple of days.

I'm getting "No Results" in the global search.

This doesn't actually seem to be related to using a belongsToMany ordering as this happens even when I only have a standard sorting happening on a single table.

These are the errors I'm seeing in my stack trace:

{
    "file": "/Users/matt/Code/Sites/redacted/vendor/optimistdigital/nova-sortable/src/Traits/HasSortableRows.php",
    "line": 13,
    "function": "newResource",
    "class": "Laravel\\Nova\\Http\\Requests\\NovaRequest",
    "type": "->"
},
{
    "file": "/Users/matt/Code/Sites/redacted/vendor/optimistdigital/nova-sortable/src/Traits/HasSortableRows.php",
    "line": 59,
    "function": "getSortability",
    "class": "App\\Nova\\Resources\\Tag",
    "type": "::"
},

Any help would be greatly appreciated! Thanks πŸ˜„

Sort controls not showing in relation tables since version 1.2.0

Before Update

laravel/framework v6.9.0
laravel/nova v2.9.2
optimistdigital/nova-sortable 1.1.3

Bildschirmfoto 2020-02-18 um 18 48 02

After Update

laravel/framework v6.15.1
laravel/nova v2.10.1
optimistdigital/nova-sortable 1.2.0

Bildschirmfoto 2020-02-18 um 18 49 37

Sorting controls are not shown in detail pages anymore. Before the update there were sorting controls (see the slight difference in the screenshots above).

However in grid views sort controls work as expected. But in my case there I really need them in the detail views as the records are group sorted.

Is this functionality coming back? Is this a bug? Are there workarounds?

Sorting while "sorted"

I can see that you have disabled the move button when the list is sorted by a column, which is great!
Sadly you can still press the up/down buttons, which does not make a lot of sense :)

Hope it will be fixed in a future release

Setting permissions on who can sort rows

Many thanks for the package!

My Nova resources are controlled through policies. Only admins can change resources, the rest just view them.

With this package, it appears that any user can reorder the rows and it will be persisted in the database, regardless of policy constraints.

Is there a way to allow only admins to change the order, and the rest would just see that arrangement?

I use Nova 2.11

Update: I uninstalled the latest version and installed v1.4.5 instead. Now the functionality works as I expect it and users who cannot manipulate resources also cannot change the row order. I guess this specific issue just crept in subsequently to v1.4.5.

Missing Sort-Buttons since 2.1.6

We use this package extensively for both sorting resources (sort_on_index) but also relations ( sort_on_has_many / sort_on_belongs_to).

In our use case, we allow to sort a resource (e.g. post) but also the relations to this resource (e.g. user->post) through the pivot table. Prior to 2.1.6 this worked, but now either sort_on_index OR sort_on_belongs_to is possible.

Would be great if you could re-enable this feature.

Note:
We had some issues to make both sort on index and sort on belongs to work, as the Nova frontend did not show the correct sorting, but the Eloquent relationship worked correctly.
Nova does not distinguish between table names. So both users.sort_order and post_user.sort_order are mapped to the same field name sort_order within the Nova frontend.
Using a different column name on the pivot table (e.g. pivot_sort_order) solved this issue.

@marispro please add if I missed something

Sort button grayed out

Possible bug ?
I followed manual, everything seem to be right but sort buttons are always disabled.
When i am passing sort_not_allowed = true - button are showing up but disabled.
When i am passing sort_not_allowed = false - buttons are not showing up at all.
I am confused.

Move items across pages

Is there a way to move an item to the next/previous page? As I see it, currently no.

Of cause Drag'n'drop is hard to manage across pages. But maybe add an extra button at the first and list item? Or use the existing arrow buttons only to move to the next page instead of the end?

Icon's don't appear in HasMany relation

Nova 3.5
Nova-sortable 1.4.7

I'm including HasSortableRows trait but icon to sort don't appear in listing.
I haven't php error and console error.
This feature was ok few month ago and I didn't modify the code, only update.
Capture d’écran de 2020-04-30 16-22-15

I don't know how explain my issue....

Composer install fails on Nova 3.4.x

I might be doing something wrong but on Laravel Nova 3.4.1 when I try to install it I get:

optimistdigital/nova-sortable 1.4.7 requires laravel/nova ^2.0.11 || ^3.0 -> no matching package found.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.