Skip to content

Commit

Permalink
improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gwleuverink committed Aug 26, 2024
1 parent 03c41ff commit 96e11e4
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ TODO: Short description
composer require leuverink/livewire-property-group
```

## Usage
## Basic Usage

```php
class Form extends Component
{
{
#[Group('a')]
public $foo = 1;
#[Group('a')]
Expand All @@ -24,7 +24,6 @@ class Form extends Component
#[Group('b')]
public $baz = 3;


public function submit()
{
$groupA = $this->group('a'); // ['foo' => 1, 'bar' => 2]
Expand All @@ -33,26 +32,64 @@ class Form extends Component
}
```

## Accessing Group Properties

```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
// Get all properties in a group
$this->group('a'); // returns ['foo' => 1, 'bar' => 2]

// 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
// Get property names
$this->group('a')->keys(); // returns ['foo', 'bar']

// Get property values
$this->group('a')->values(); // returns [1, 2]

// Iterate over properties
$this->group('a')->each(fn() => /* */);
```

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

```php
// 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();
```

## Working with Multiple Groups

```php
// Perform operations on multiple groups
$this->group(['a', 'b']);

// Validate multiple groups
$this->group(['a', 'b'])->validate();
```

## Debugging

```php
// Dump group properties
$this->group('a')->dump();

// dd group properties
$this->group('a')->dd();

// Dump is chainable
$validated = $this->group('a')
->dump()
->validate();
```

<br />
<hr />
<br />

## Development

```bash
Expand Down

0 comments on commit 96e11e4

Please sign in to comment.