headlesslaravel / fields
Structure frontend fields with PHP
Requires
- illuminate/support: ^10.0
Requires (Dev)
- phpunit/phpunit: ^10
README
A Laravel package that simplifies the process of formatting fields for display and forms in your Inertia.js projects. With this package, you can easily define Vue components, and populate data when needed. This package is particularly useful for developers working with Laravel, Inertia.js, and Vue.js.
Table of Contents
Installation
To install the Laravel Inertia Field Formatter package, you can use Composer:
composer require headlesslaravel/fields
Usage
After installing the package, you can use the Fields
class to create form and display field configurations. These configurations can be used to define Vue components and populate data when necessary.
To create a form field configuration, you can use the Fields::form()
method:
$fields = Fields::form([ // Your field configurations ]);
To create a display field configuration, you can use the Fields::display()
method:
$fields = Fields::display([ // Your field configurations ], $data);
Both methods accept an array of field configurations. You can create field configurations using the Text::make()
method. The first parameter is the label for the field, and the second parameter is an optional key that will be used to populate data for display fields.
You can also chain additional properties to the field configuration, like setting the span
property for the grid system:
Text::make('First Name')->prop('span', 6)
Examples
Here is a more generic example of using the Laravel Inertia Field Formatter package:
// Form field configuration $formFields = Fields::form([ Text::make('First Name')->prop('span', 6), Text::make('Last Name')->prop('span', 6), Text::make('Email')->prop('span', 6), Text::make('Phone')->prop('span', 6), ]); // Display field configuration $displayFields = Fields::display([ Text::make('Name', 'name'), Text::make('Email', 'email'), Text::make('Phone', 'phone'), ], $user); // Return the field configurations as an array return [ 'form' => $formFields, 'display' => $displayFields, ];
Available Fields
Contributing
Contributions are welcome! If you find a bug or have a suggestion, please open an issue on the GitHub repository. If you'd like to contribute code, please submit a pull request.
License
This package is released under the MIT License.