New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

performing/laravel-field-attributes

This is my package laravel-field-attributes
2,297 1
Install
composer require performing/laravel-field-attributes
Latest Version:1.1.0
PHP:^8.4
Laravel:10 – 13
License:MIT
Last Updated:Jul 26, 2026
Links: GitHub  ·  Packagist
Maintainer: giorgiopogliani

laravel-field-attributes

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Simple package to decorate classes with field attributes, allowing you to easily convert data objects to forms with labels and descriptions.

Installation

You can install the package via composer:

composer require performing/laravel-field-attributes

Usage

class MyDto 
{
    use FieldAttributes;

    public function __construct(
        #[Field(label: 'Name', description: 'Enter your full name')]
        public string $name,
        #[Field(label: 'Email', description: 'Enter your email address')]
        public string $email,
    ) {}
}

$instance = new MyDto('John Doe', 'john@example.com');

$instance->getFieldValues(); 
// ['name' => 'John Doe', 'email' => 'john@example.com']

$instance->getFieldDefinitions(); 
// [
//    'name' => ['label' => 'Name', 'description' => 'Enter your full name', 'type' => 'string', 'required' => true, 'value' => 'John Doe'],
//    'email' => ['label' => 'Email', 'description' => 'Enter your email address', 'type' => 'string', 'required' => true, 'value' => 'john@example.com']
// ]

If you combine this with spatie/laravel-data, you can also add validation on top, serialize and deserialize as JSON back and forth from the database.

In the package there is also a caster ObjectCast which can cast a json column to an object, it takes the class name from a type column of the eloquent model. You can also map types to specifc classes in the config.

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

Related Packages

reedware/nova-field-manager

Creates a field facade for referencing fields.

7,002 0
thettler/laravel-console-toolkit

This Package provides some usefully console features like the attribute syntax f...

4,095 32
typerocket/laravel

Makes form building and model binding a breeze.

3,816 10
cspray/annotated-container

Create Dependency Injection containers configured with PHP8 Attributes.

1,534 42

Version History

Version Released PHP Laravel License
1.1.0 ^8.4 ^10.0||^11.0||^12.0|^13.0 MIT
1.0.3 ^8.4 ^10.0||^11.0||^12.0 MIT
1.0.2 ^8.4 ^10.0||^11.0||^12.0 MIT
1.0.1 ^8.4 ^10.0||^11.0||^12.0 MIT
1.0 ^8.4 ^10.0||^11.0||^12.0 MIT