leuverink/livewire-property-groups

Livewire Attribute for grouping properties
484 12
Install
composer require leuverink/livewire-property-groups
Latest Version:2.0.0
PHP:^8.1
License:MIT
Last Updated:Nov 14, 2025
Links: GitHub  ·  Packagist
Maintainer: gwleuverink

Livewire Property Groups

codestyle tests

This package simplifies property management, validation, and manipulation in Livewire components by allowing you to organize related properties into named groups.

Installation

composer require leuverink/livewire-property-groups

Basic Usage

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();

        //...
    }
}


Accessing Group Properties

Use the WithGroups trait within your Component or Form object to get access to the group method.


// 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;

Proxying Livewire Methods


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

Working with Multiple Groups


// Retrieve properties from multiple groups
$this->group(['a', 'b']);

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

Debugging


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

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

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

Volt

In class-based components, property groups work like any other Livewire component. When using Volt's functional API you may use property groups like demonstrated below.


use Leuverink\PropertyAttribute\Group;
use Leuverink\PropertyAttribute\WithGroups;
use function Livewire\Volt\{action, state, uses};


uses([WithGroups::class]);

state([
    'foo' => 1,
])->attribute(Group::class, 'a');

state([
    'bar' => 2,
    'baz' => 'Lorem',
])->attribute(Group::class, 'b');

$action = action(function() {
    $groupA = $this->group('a')
        ->validate()
        ->values();

    $groupB = $this->group('b')
        ->validate()
        ->values();

    // ...
});

Conflicting group method signature

I realize that group is a very generic method name that you might well use inside your own components. You may change the method signature by providing an alias.

use WithGroups {
    group as fooBar;
}

Development

composer lint # run all linters
composer fix # run all fixers

composer analyze # run static analysis
composer baseline # generate static analysis baseline

License

This package is open-source software licensed under the MIT license.

Related Packages

erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

612,604,198 9,704
laravel/framework

The Laravel Framework.

551,557,428 34,802
laravel/tinker

Powerful REPL for the Laravel framework.

462,518,693 7,436