Skip to content

Commit

Permalink
add crude examples to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gwleuverink committed Aug 26, 2024
1 parent c4e7cb8 commit 4e2f62e
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,43 @@ composer require leuverink/livewire-property-group

## Usage

TODO
```php
class Form extends Component
{
#[Group('a')]
public $foo = 1;
#[Group('a')]
public $bar = 2;

#[Group('b')]
public $baz = 3;


public function submit()
{
$groupA = $this->group('a'); // ['foo' => 1, 'bar' => 2]
$groupB = $this->group('b'); // ['baz' => 3]
}
}
```

```php
// Behaves like a Collection
$this->group('a'); // returns all properties ['foo' => 1, 'bar' => 2]
$this->group('a')->keys(); // returns all property names ['foo', 'bar']
$this->group('a')->values(); // returns all property values [1, 2]
$this->group('a')->each(fn() => /* */); // iterate over properties

// Proxies Livewire calls
$this->group('a')->reset(); // resets properties to initial state
$this->group('a')->pull(); // returns all properties & resets properties to initial state
$this->group('a')->validate(); // validates all properties in a group

// Extra
$this->group(['a', 'b']); // all operations can be applied to any number of groups
$this->group(['a', 'b'])->validate(); // especially handy when validating

```

## Development

Expand Down

0 comments on commit 4e2f62e

Please sign in to comment.