Comments (2)
Do this on your own model, such methods should potentially update a lot of records. There are multiple ways to do this. We try to keep this package very simple.
from eloquent-sortable.
I ended up creating a PHP package with support for custom resolution on objects (like Eloquent models). If you change your mind, I can try to make a PR to add it on the package. This is currently how I use it on my project:
declare(strict_types=1);
namespace App\Services;
use App\Models\Aisle;
use Illuminate\Support\Facades\DB;
use Khalyomede\ReorderBeforeAfter\Item;
use Khalyomede\ReorderBeforeAfter\Listing;
use Khalyomede\ReorderBeforeAfter\Placement;
final class AisleService
{
public function reorder(Aisle $aisle, Aisle $reference, string $placement): void
{
$listing = Listing::outOf($aisle->store->aisles->all(), fn (Aisle $aisle): Item => new Item($aisle, $aisle->order));
$listing->matchWith(fn (Aisle $left, Aisle $right): bool => $left->is($right));
$listing->applyWith(function (Item $item): void {
$aisle = $item->value;
if ($aisle->order !== $item->order) {
$aisle->order = $item->order;
$aisle->save();
}
});
DB::beginTransaction();
if ($placement === "before") {
$listing->reorder($aisle, Placement::Before, $reference);
} else {
$listing->reorder($aisle, Placement::After, $reference);
}
DB::commit();
}
}
I will ask if Laravel developers are interested about it on my Twitter in the mean time.
https://github.com/khalyomede/reorder-before-after
from eloquent-sortable.
Related Issues (20)
- Feature request: Zero based index
- How to sort all by desc in a resource?
- Changing the sort breaks the sort if the model uses scopeOrdered() HOT 1
- Not firing model events when changing order HOT 4
- Order is getting overwritten when creating HOT 2
- syntax error, unexpected 'static' (T_STATIC) in SortableTrait.php
- Possible Duplicate Order Values?
- actions belongsToMany
- Readme is inconsistent. HOT 1
- Nullable Order HOT 1
- Unknown column 'order_column'
- Sort when creating doesn't work with polymrphic pivot models.
- Sort values not generated on MorphPivot table
- Problems when using ordered or orderBy HOT 2
- Disabling sorting when replicating
- 有一种情况下, 调用 moveOrderUp 上移操作可能会不准确。 HOT 2
- setNewOrder ignores "buildSortQuery"
- Duplication of item (hasMany) HOT 1
- moveToStart updates wrong rows HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eloquent-sortable.