Homepage
Main navigation
Main content
Additional information
October Tricks
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
October CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
The `Sortable` trait as well as the `ReorderController` behaviour require all models to have a consistent `sort_order` value. If you are adding the `Sortable` trait for an existing set of models, you might get the following error message when trying to sort the models via the backend: ``` Illuminate\Database\QueryException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column `db`.`acme_plugin_table`.`sort_order` at row 1 ``` This is because all of your models currently have a `sort_order` value of `NULL` or `0`. To fix this issue, simply run the following statement in a `php artisan tinker` session. It will set initial `sort_order` values for each model. You can set the inital order by editing the `orderBy` statement according to your data. ```php Vendor\YourPlugin\Models\YourModel ::orderBy('title') // Change this to modify the inital order ->get() ->map(function($model, $index) { $model->sort_order = $index + 1; $model->save(); }); ``` Console friendly version for pasting after your model query: ```php ->get()->map(function($model, $index) {$model->sort_order = $index + 1;$model->save();}); ```
References
Add additional online resources to your trick
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline