You probably have noticed that we have "Active" toggle in the table. Let's implement its behavior, so you could click on that Toggle to change the value immediately, without leaving the table page.
This is the expected result, visually:

You might have seen that in Categories migration we have a column is_active, so we will change its value in the database.
First, we need a public property in the Livewire Component. It will be an array and called $active...
How can we apply a newer @checked blade directive?
I don't think we can apply it here.
Getting Error
Attempt to read property "index" on null
I thank something is missing, but What, and where should it be?
Why are we creating an in-memory dictionary (an associative array with same structure for all key-value pairs) to hold the value from each category's
is_activeproperty?Couldn't we just bind the toggling to the
is_activeof the current iterated$categoryinside the loop?I did that and got the same result, with more performance and readability: the
activearray does not need to be recreated on every update in$categories; thetoggleIsActivereceives as argument the$categoryitself rather than its id (thus no need to fetch it in the database: we just update it directly).e.g: