Home > Blockchain >  how can i get how many checkboxes are checked in laravel livewire
how can i get how many checkboxes are checked in laravel livewire

Time:09-09

This table and i need once the user selects checkbox,the number of selected (0 in pic) updated and save this value

table contain select all checkbox and the second for the single checkbox and some text table

the code for the first checkbox for select all checkbox and the second for the single checkbox the code for the first checkbox for select all checkbox and the second for the single checkbox

CodePudding user response:

In your component you want to have an array to hold the selected checkboxes in:

public array $selectedItems = [];

Then, in your blade you want to link your checkbox to this array:

<input type="checkbox" value="{{ $item->id }}" wire:model="selectedItems">

Now you can count($selectedItems) in your blade, or count($this->selectedItems) in your component to know how many are selected.

CodePudding user response:

Try something like this

<input
id="my-id"
wire:model="yourCheckboxModel"
type="checkbox"
@if($yourLivewireVariable)
checked
@endif>

You can use a blade if endif statement to toggle the checked variable, and then use wire model to bound the variable

  • Related