-
-
Save ramaID/26f655424b326402a809ae41ffbca494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* In your Livewire blade for the list of items | |
*/ | |
<ul wire:sortable="saveOrderChange"> | |
@foreach($this->list as $item) | |
<li | |
wire:sortable.item="{{ $item->id }}" | |
wire:key="{{ $item->id }}" | |
> | |
Content here | |
</li> | |
@endforeach | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* In your Livewire model for the list of items | |
*/ | |
class ItemList extends Component | |
{ | |
// rest of component | |
public function saveOrderChange($sortableEvent) | |
{ | |
// Convert the sortable event into an array of positions for the setNewOrder function | |
$order = array_map(function ($item) { | |
return intval($item['value']); | |
}, $sortableEvent); | |
// probably a better way to do this, but this was my in 2 mins solution and I haven't gotten back to it yet | |
$this->list->items()->first()->setNewOrder($order); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment