Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Livewire Bulk Actions Pattern

Implement bulk selection and actions in data tables.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Component
  2. View

Bulk actions pattern:

Component

php
public array $selected = [];
public bool $selectAll = false;

public function updatedSelectAll($value)
{
    $this->selected = $value 
        ? $this->users->pluck('id')->toArray() 
        : [];
}

public function deleteSelected()
{
    User::whereIn('id', $this->selected)->delete();
    $this->selected = [];
}

View

blade
<input type="checkbox" wire:model.live="selectAll">

@foreach($users as $user)
    <input type="checkbox" value="{{ $user->id }}" wire:model.live="selected">
@endforeach

<button wire:click="deleteSelected" @disabled(empty($selected))>
    Delete Selected ({{ count($selected) }})
</button>
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read