Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ux Sortable Laravel Package

aymericcucherousset/ux-sortable

View on GitHub
Deep Wiki
Context7

Usage with LiveComponents

Symfony UX Sortable integrates seamlessly with Symfony UX LiveComponent for dynamic, interactive lists.

1. Create a Twig Component

Twig template:
File: templates/components/TestList.html.twig

<div {{ attributes }}>
    <ul {{ sortable_attributes(
        { animation: 300 },
        { prefix: 'reorder' }
    ) }}>
        {% for item in items %}
            <li data-id="{{ item.id }}">
                {{ item.name }}
            </li>
        {% else %}
            <li>No items</li>
        {% endfor %}
    </ul>
</div>

PHP component:
File: src/Twig/Components/TestList.php

<?php

namespace App\Twig\Components;

use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveArg;
use Symfony\UX\LiveComponent\Attribute\LiveListener;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent]
final class TestList
{
    use DefaultActionTrait;

    #[LiveProp(writable: true)]
    public array $items = [];

    #[LiveListener(eventName: 'reorder.end')]
    public function reorder(
        #[LiveArg()] array $order,
        #[LiveArg()] array $ids,
        #[LiveArg()] int $oldIndex,
        #[LiveArg()] int $newIndex,
    ): void
    {
        $item = $this->items[$oldIndex];

        array_splice($this->items, $oldIndex, 1);

        array_splice($this->items, $newIndex, 0, [$item]);

        // Handle reordered items (example: dump for debug)
        dd($this->items);
    }
}

2. Use the Component in a Page

{{ component('TestList', {
    items: [
        { id: 1, name: 'Item 1' },
        { id: 2, name: 'Item 2' },
        { id: 3, name: 'Item 3' },
    ],
}) }}

How it works

  • The sortable_attributes helper generates the necessary Stimulus data attributes.
  • The prefix option (e.g., 'reorder') customizes the event name emitted on reorder.
  • The LiveListener listens for the reorder.end event and updates the items array accordingly.

Result:
Drag & drop reordering is fully reactive, and the component updates automatically.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc