A checkbox in each cell
->checkbox() puts a checkbox in each cell. A checked cell is saved as true; an unchecked one is left out.
Note: Try it
Click anywhere in the Sales associate × Refunds cell: it is checked. Click “Show what would be saved”: "orders.refund": true is now under associate.
|
Role
|
View
|
Edit
|
Stock
|
Refunds
|
Reports
|
|---|---|---|---|---|---|
|
Owner
|
|||||
|
Store manager
|
|||||
|
Sales associate
|
|||||
|
Accountant
|
|||||
|
Seasonal helper
|
Check a whole row or column at once
->bulkToggleable() adds a small round button next to each role and each permission. It is shown faintly at all times and gets darker when you point at the name. It checks every cell of its row or column, or unchecks them all if they are all checked already. The button next to “Role” in the corner does the whole table.
Note: Try it
Click the round button next to “Seasonal helper” on the left: the whole row is checked. Click it again: the whole row is unchecked. Do the same with “Reports” at the top for a column.
|
Role
|
View
|
Edit
|
Stock
|
Refunds
|
Reports
|
|---|---|---|---|---|---|
|
Owner
|
|||||
|
Store manager
|
|||||
|
Sales associate
|
|||||
|
Accountant
|
|||||
|
Seasonal helper
|
Roles in groups
Give ->rows() an array of arrays: the outer keys (In the store, Outside the store) are written as a line above their roles.
Note: Try it
Look at the left of the table: Owner, Store manager and Sales associate are under “In the store”, Accountant and Seasonal helper under “Outside the store”.
|
Role
|
View
|
Edit
|
Stock
|
Refunds
|
Reports
|
|---|---|---|---|---|---|
| In the store | |||||
|
Owner
|
|||||
|
Store manager
|
|||||
|
Sales associate
|
|||||
| Outside the store | |||||
|
Accountant
|
|||||
|
Seasonal helper
|
|||||
Saved in a table, with the Owner row locked
A page with no record reads and saves with ->store(MatrixStore::make(RolePermission::class, row: 'role', column: 'permission')): a row in role_permissions means the cell is checked. The Save button calls saveToStore(), which writes only the cells you changed. ->disabledCells() locks the Owner row: it is shown but cannot be changed, and the server keeps it as saved.
Note: Try it
Check Accountant × View and click Save permissions: the message says 1 added. Reload the page: it is still checked. Uncheck it, save again: the message says 1 removed, and it stays unchecked after a reload. Try to click a cell in the Owner row: nothing changes.
|
Role
|
View
|
Edit
|
Stock
|
Refunds
|
Reports
|
|---|---|---|---|---|---|
| In the store | |||||
|
Owner
|
|||||
|
Store manager
|
|||||
|
Sales associate
|
|||||
| Outside the store | |||||
|
Accountant
|
|||||
|
Seasonal helper
|
|||||