PHP code example of leuverink / livewire-property-groups
1. Go to this page and download the library: Download leuverink/livewire-property-groups 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/ */
leuverink / livewire-property-groups example snippets
use Leuverink\PropertyAttribute\Group;
use Leuverink\PropertyAttribute\WithGroups;
class Form extends Component
{
use WithGroups;
#[Group('a')]
public $foo = 1;
#[Group('a')]
public $bar = 2;
#[Group('b')]
public $baz = 3;
public function submit()
{
$this->group('a')->validate();
//...
}
}
// Get all properties in a group
$this->group('a'); // ['foo' => 1, 'bar' => 2]
// Get property names
$this->group('a')->keys(); // ['foo', 'bar']
// Get property values
$this->group('a')->values(); // [1, 2]
// Iterate over properties
$this->group('a')->each(fn($value, $name) => /* */);
// Get all grouped properties, excluding non grouped
$this->group();
// Access a group as an array or an object
$this->group('a')['foo'];
$this->group('a')->foo;
// Reset properties to initial state
$this->group('a')->reset();
// Return all properties and reset to initial state
$this->group('a')->pull();
// Validate all properties in a group
$this->group('a')->validate();
// Works inside a form object
$this->userForm->group('a')->validate();
// Retrieve properties from multiple groups
$this->group(['a', 'b']);
// Validate multiple groups
$this->group(['a', 'b'])->validate();
// dump group properties
$this->group('a')->dump();
// dd group properties
$this->group('a')->dd();
// dump is chainable
$validated = $this->group('a')
->dump()
->validate();