Skip to content
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

Is is possible in belongsToSortedMany set a new item position 1 and also reorder other item #76

Closed
alexpisotsky opened this issue Aug 14, 2020 · 1 comment

Comments

@alexpisotsky
Copy link

Sdantard works module, all new items have order number last item + 1. Is it possible when a new item will be first (has position 1) and other items will be reordered automatically?

@boxfrommars
Copy link
Owner

You can do it by moving new item before the first item. Something like:

$post->tags()->save($newTag); // add new tag
$firstTag = $post->tags()->first(); // get first tag
$post->tags()->moveBefore($newTag, $firstTag); // move new tag before first tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants