Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Jakub003's avatar

Livewire Sortable Group Eloquent Query?

This is probably a huge newb question, but I can't seem to find any tutorials or examples for how to write out the livewire public function to make the group thing work. Any links to a guide would be much appreciated as well :)

In this documentation https://github.com/livewire/sortable there is only an example of the blade view. I was able to find how to make the sortable work in some demos for a single item.

To drag around the order of some subtasks, I did this. Since only one column value needs to be changed, I kinda understand this eloquent query... I am really lost on how this is supposed to work to drag and drop cards between columns like on trello.

public function updateCardTaskOrder($cardtasks)
    {
        foreach($cardtasks as $cardtask) {
            Cardtask::find($cardtask['value'])->update(['order' => $cardtask['order']]);
        }

        $this->cardtasks = Cardtask::where('card_id', $this->card_id)
            ->orderBy('order', 'ASC')
            ->get();
    
    }

Q1. How would I change the public function to update the order along with the column_id?

Q2. I think I setup the group thing right?

<div wire:sortable="updateColumnOrder" wire:sortable-column="updateTaskOrder">
    @foreach ($columns as $column)
        <div wire:key="column-{{ $column->id }}" wire:sortable.item="{{ $column->id }}">

            <ul wire:sortable-column.item-column="{{ $column->id }}">
                @foreach ($tasks as $task)
                    <li wire:key="task-{{ $task->id }}" wire:sortable-column.item="{{ $task->id }}">
                          // Show card stuff
                    </li>
                @endforeach
            </ul>
            
        </div>
    @endforeach
</div>

enter image description here

Any advice in general is much appreciated regarding this :)

0 likes
5 replies
vincent15000's avatar

Hello,

I don't understand ... if you want to update the order, you have to implement an updateColumnOrder function in your component.

In the view, you could have something like this : updateColumnOrder({{ $new_order }}).

Jakub003's avatar

Yea that is the part I am lost on.

How would I write the function so that it updates 2 values at the same time. One which would be what order a card is in a given column, and the second value being what column it is in?

I was able to get this far to make this work with a single dimension thing.


 public function updateTaskOrder($tasks)
    {
        foreach($tasks as $task) {
            Task::find($task['value'])->update(['order' => $task['order']]);
        }

    
    }

How do you also update the column the task is in as well?

vincent15000's avatar

I don't understand where is the problem. You can pass 2 parameters to the update function.

Jakub003's avatar

I am new to coding, and eloquent queries are a bit over my head still.

That is essentially my question, how do I set up the update function to pass both the order and column_id?

Jakub003's avatar

I just learned that this can't be done with livewire sortable >.<

Sorry for all the confusion

Please or to participate in this conversation.