Warning
This package is still in development. It is not yet ready for production use and the API may change at any time.
Let your users specify custom attributes for models in Filament, similar to Custom Fields in WordPress.
Demonstration: showing the creation of a custom user attribute for the 'Locations' resource of this app:
demonstration.mp4
In this demonstration:
- A checkbox is added and it's order in the table and form is specified.
- The checkbox is displayed in the table and form. Users can now toggle the checkbox and view the value in the table.
Note
This is a third-party package not affiliated with Filament or Laravel.
-
Make sure your project meets these requirements:
- PHP 8.1 or higher
- Livewire 3.0.3 or higher
- Filament 3.0 or higher
- A database that supports JSON columns, e.g:
- MySQL 5.7.8 or higher
- PostgreSQL 9.2 or higher
- SQLite 3.38 or higher
-
Install the package via composer:
composer require luttje/filament-user-attributes
-
Run the following command to fully install the package:
php artisan filament-user-attributes:install
This publishes the migrations to create the two required tables and runs them.
-
Run the wizard command to help you setup your project code:
php artisan filament-user-attributes:wizard
The wizard will help you:
- Specify which models should have custom user attributes
- Setup a model that can configure the user attributes for each user (e.g. a user or tenant model)
- Setup resources that the configuration model can configure custom attributes for
Finally you need to show the user attributes configuration form somewhere. That way users can actually configure their custom attributes for the resource.
-
Create a resource and inherit from the
UserAttributeConfigResource
class:// app/Filament/Resources/UserAttributeConfigResource.php namespace App\Filament\Resources; use Luttje\FilamentUserAttributes\Filament\Resources\UserAttributeConfigResource as BaseUserAttributeConfigResource; class UserAttributeConfigResource extends BaseUserAttributeConfigResource { protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; }
Or you can create your own resource from scratch. See the source code for inspiration.
🎉 That was all, you and your users can now configure custom attributes!
Your users (or tenants) can now configure custom attribute fields:
The configured custom attributes are (optionally) added to the resource form and table:
-
To modify translations, publish the translations file:
php artisan vendor:publish --tag=filament-user-attributes-translations
-
To modify the configuration, publish the configuration file:
php artisan vendor:publish --tag=filament-user-attributes-config
- Add custom attributes to any model
- Support for UUIDs
- Support for ULIDs
- Easily display the attributes in a Filament form
- Easily display the attributes in a Filament table
- Sensible validations for input types
- Allow users to specify order of attributes
- In the form
- In the table
- Allow users to hide attributes
- In the form
- In the table
- Users can specify default values for attributes
- Users can specify if attributes are required
- Users can specify if attributes inherit their value from another attribute, even from a related model
- For Resources
- For Livewire components (if they implement the static
::getModel()
method) - For related fields that have a {relation}_id field in the form
- For related attributes that have no field in this form
- User interface for managing user attributes
- Support for Tabs and Sections in the form
- Wizard command to help you setup your project code
Supported Input types:
- Text
- Textarea
- Number
- Integer
- Decimal
- Specific range
- Specific decimal places
- Select
- Specific options
- From an existing model property
- Radio
- Specific options
- From an existing model property
- Tags
- With suggestions
- Date
- Date
- Time
- Date and time
- Checkbox
- With default
- Toggle
- With default
- File
- Image
- Other
- Preview
- Color
Please see CONTRIBUTING for details on how to contribute to this project. You'll also find instructions on how to run the tests.