PHP code example of pavloniym / nova-checkbox-matrix
1. Go to this page and download the library: Download pavloniym/nova-checkbox-matrix library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pavloniym / nova-checkbox-matrix example snippets
use Pavloniym\NovaCheckboxMatrix\CheckboxMatrix;
use Pavloniym\NovaCheckboxMatrix\MatrixColumn;
use Pavloniym\NovaCheckboxMatrix\MatrixOptions;
use Pavloniym\NovaCheckboxMatrix\MatrixRow;
use Pavloniym\NovaCheckboxMatrix\MatrixValue;
CheckboxMatrix::make('Team', 'members')
->columns([
MatrixColumn::make('translator', 'Translator'),
MatrixColumn::make('voice_actor', 'Voice actor'),
MatrixColumn::make('sound_engineer', 'Sound engineer'),
])
->rows($users->map(fn (User $user) => MatrixRow::make($user->id, $user->name)
->subtitle('@' . $user->username) // second line
->caption($user->position) // third line
->avatar($user->avatar_url))) // absolute http(s) URL, initials otherwise
->options(MatrixOptions::make()
->searchable() // default: false
->avatars(true) // default: true
->subtitles(true) // default: true
->captions(true) // default: true
->counters(true)) // default: true
->default(MatrixValue::fromArray([$userId => ['translator']]));
use Pavloniym\NovaCheckboxMatrix\MatrixValue;
public function handle(ActionFields $fields, Collection $models)
{
/** @var MatrixValue|null $value null when the field was not submitted at all */
$value = $fields->get('members');
foreach ($value?->selections() ?? [] as $selection) {
$selection->rowKey; // string
$selection->columnKeys; // list<string>, in column order
}
$value?->forRow($userId); // ?MatrixSelection
$value?->isEmpty(); // true when every checkbox is cleared
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.