performing/laravel-field-attributes

This is my package laravel-field-attributes
2,185 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

puz/multicolumnauth

Makes it possible to log in with both a username and / or email

13 1
gregoriohc/laravel-attributum

Laravel package that adds custom dynamic attributes to models

10 2
davidmpeace/immutability

A simple Laravel package that allows you to enforce immutable attributes on Eloq...

20,475 6

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