### Install Custom Fields Package Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Install the package using Composer. The service provider is auto-discovered, and migrations are run automatically. ```bash composer require aureuserp/custom-fields ``` ```bash php artisan migrate ``` -------------------------------- ### Custom Fields Configuration File Example Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Example of the publishable `config/custom-fields.php` file. This file allows for app-wide configuration of navigation and resource settings for the custom fields plugin. ```php // config/custom-fields.php return [ 'navigation' => [ 'label' => 'Custom Fields', 'group' => 'Settings', 'icon' => 'heroicon-o-puzzle-piece', 'sort' => 50, 'badge' => null, 'register'=> true, ], 'resource' => [ 'register' => true, 'slug' => 'admin/custom-fields', 'cluster' => \App\Filament\Clusters\AdminTools::class, 'model_label' => null, 'plural_model_label' => null, ], ]; ``` -------------------------------- ### Configure Custom Fields Plugin via Fluent Setters Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Example of configuring the CustomFieldsPlugin within a Filament panel provider using fluent setters. This method is recommended for per-panel overrides. ```php // app/Providers/Filament/AdminPanelProvider.php use Webkul\CustomFields\CustomFieldsPlugin; ->plugins([ CustomFieldsPlugin::make() ->navigationGroup(__('admin.navigation.setting')) ->navigationLabel('Custom Fields') ->navigationIcon('heroicon-o-puzzle-piece') ->navigationSort(50) ->navigationBadge(fn () => \Webkul\CustomFields\Models\Field::count()) ->navigationBadgeColor('primary') ->slug('admin/custom-fields') ->cluster("App\Filament\Clusters\AdminTools"::class), ]) ``` -------------------------------- ### Employee Resource with Custom Fields Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Example of an Employee resource that uses the HasCustomFields trait to merge custom form fields and table columns. Ensure the trait is used in both the Resource and the Eloquent model. ```php use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Resources\Resource; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; use Webkul\CustomFields\Filament\Concerns\HasCustomFields; use Webkul\Employee\Models\Employee; class EmployeeResource extends Resource { use HasCustomFields; protected static ?string $model = Employee::class; public static function form(Schema $schema): Schema { return $schema->components(static::mergeCustomFormFields([ TextInput::make('name')->required(), Select::make('department_id')->relationship('department', 'name'), ])); } public static function table(Table $table): Table { return $table ->columns(static::mergeCustomTableColumns([ TextColumn::make('name'), ])) ->filters(static::mergeCustomTableFilters([])); } } ``` -------------------------------- ### Eloquent Model with Custom Fields Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Example of an Employee Eloquent model that uses the HasCustomFields trait. Custom fields defined in the admin interface will automatically be fillable and castable (e.g., to arrays). ```php use Webkul\CustomFields\Concerns\HasCustomFields; class Employee extends Model { use HasCustomFields; protected $fillable = ['name', 'department_id']; } // After an admin defines a "hobbies" checkbox_list field: $employee = Employee::create([ 'name' => 'Alice', 'department_id' => 1, 'hobbies' => ['chess', 'hiking'], // ← custom field, automatically fillable + cast to array ]); $employee->hobbies; // ['chess', 'hiking'] ← automatically cast from JSON ``` -------------------------------- ### Use FieldType Enum with Fallback Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Safely get a FieldType enum case from a raw value, falling back to the default if the value is not recognized. ```php use Webkul\CustomFields\Enums\FieldType; use Webkul\CustomFields\Enums\InputType; $type = FieldType::tryFrom($raw) ?? FieldType::default(); ``` -------------------------------- ### Build Filament Infolist Entries with CustomEntries::make() Source: https://context7.com/aureuserp/custom-fields/llms.txt Generates Filament infolist entry objects for display-only views. Can include or exclude specific fields. Ensure `CustomEntries` is imported. ```php use Webkul\CustomFields\Filament\Infolists\Components\CustomEntries; use App\Filament\Resources\EmployeeResource; $entries = CustomEntries::make(EmployeeResource::class)->getSchema(); // With include/exclude: $entries = CustomEntries::make(EmployeeResource::class) ->include(['hobbies', 'certifications']) ->exclude(['internal_notes']) ->getSchema(); ``` ```php use Filament\Infolists\Infolist; use Filament\Infolists\Components\Section; use Webkul\CustomFields\Filament\Infolists\Components\CustomEntries; public static function infolist(Infolist $infolist): Infolist { return $infolist->schema([ Section::make('Custom Attributes') ->schema(CustomEntries::make(static::class)->getSchema()), ]); } ``` -------------------------------- ### Publish Custom Fields Configuration File Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Command to publish the custom fields configuration file. This allows for app-wide default settings. ```bash php artisan vendor:publish --tag="custom-fields-config" ``` -------------------------------- ### Troubleshoot Policy Denies Everything Source: https://github.com/aureuserp/custom-fields/blob/master/README.md If policies are denying all actions, generate the Shield policies for `FieldResource` using the provided Artisan command. ```bash php artisan shield:generate --resource=FieldResource ``` -------------------------------- ### Run Custom Fields Plugin Code Pinting Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Format the custom fields plugin code according to Pint standards. ```bash vendor/bin/pint plugins/aureuserp/custom-fields ``` -------------------------------- ### Troubleshoot Missing Custom Fields Table Source: https://github.com/aureuserp/custom-fields/blob/master/README.md If the `custom_fields` table is missing, run the Artisan migrate command to create it. ```bash php artisan migrate ``` -------------------------------- ### Troubleshoot Class Not Found Error Source: https://github.com/aureuserp/custom-fields/blob/master/README.md If you encounter a 'Class not found' error for `Webkul\CustomFields\…`, run `composer dump-autoload` and `php artisan optimize:clear`. ```bash composer dump-autoload && php artisan optimize:clear ``` -------------------------------- ### Publish Custom Fields Resources Source: https://context7.com/aureuserp/custom-fields/llms.txt Use Artisan commands to publish the plugin's configuration file, migrations, and translation files to your Laravel project. ```bash # Publish config (config/custom-fields.php): php artisan vendor:publish --tag="custom-fields-config" # Publish migrations: php artisan vendor:publish --tag="custom-fields-migrations" # Publish translations (lang/vendor/custom-fields/): php artisan vendor:publish --tag="custom-fields-translations" ``` -------------------------------- ### Publish Custom Fields Plugin Resources Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Use these Artisan commands to publish the configuration, migrations, and translations for the custom fields plugin. ```bash php artisan vendor:publish --tag="custom-fields-config" ``` ```bash php artisan vendor:publish --tag="custom-fields-migrations" ``` ```bash php artisan vendor:publish --tag="custom-fields-translations" ``` -------------------------------- ### Run Custom Fields Plugin Feature Tests Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Execute the feature tests for the custom fields plugin using Pest. ```bash vendor/bin/pest plugins/aureuserp/custom-fields/tests/Feature ``` -------------------------------- ### Publish Custom Field Translations Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Command to publish the translation files for custom fields. This allows for customization of validation rules, Filament setting names, and other labels. ```bash php artisan vendor:publish --tag="custom-fields-translations" ``` -------------------------------- ### Troubleshoot Custom Column Not Appearing Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Verify that `CustomFieldsColumnManager::createColumn()` was called during the save process (from `CreateField::afterCreate()`) and that the host table exists. ```php CustomFieldsColumnManager::createColumn() ``` ```php CreateField::afterCreate() ``` -------------------------------- ### Merge Custom Infolist Entries in Filament Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Use this static helper to merge custom infolist entries with base entries in a Filament resource. Specify fields to include or exclude. ```php static::mergeCustomInfolistEntries(array $base, array $include = [], array $exclude = []): array ``` -------------------------------- ### Build Filament Table Filters with CustomFilters::make() Source: https://context7.com/aureuserp/custom-fields/llms.txt Generates Filament filter objects for fields marked `use_in_table = true` and `filterable`. Exposes `getQueryBuilderConstraints()` for advanced query building. Ensure `CustomFilters` is imported. ```php use Webkul\CustomFields\Filament\Tables\Filters\CustomFilters; use App\Filament\Resources\EmployeeResource; // Standard filters (SelectFilter, Filter, etc.): $filters = CustomFilters::make(EmployeeResource::class)->getFilters(); // Query builder constraints (TextConstraint, NumberConstraint, etc.): $constraints = CustomFilters::make(EmployeeResource::class) ->include(['hobbies', 'birth_year']) ->getQueryBuilderConstraints(); ``` ```php use Filament\Tables\Table; use Webkul\CustomFields\Filament\Tables\Filters\CustomFilters; public static function table(Table $table): Table { return $table ->filters(CustomFilters::make(static::class)->getFilters()) ->queryBuilderConstraints(CustomFilters::make(static::class)->getQueryBuilderConstraints()); } ``` -------------------------------- ### Create and Query Custom Fields Source: https://context7.com/aureuserp/custom-fields/llms.txt Use the `Field` model to create new custom fields with various configurations, including input type, options, form settings, and table settings. Query existing fields for a specific model, ordered by their sort position. ```php use Webkul\CustomFields\Models\Field; // Create a multiselect field for the Employee model: $field = Field::create([ 'code' => 'hobbies', 'name' => 'Hobbies', 'type' => 'select', 'input_type' => null, 'is_multiselect' => true, 'options' => ['chess', 'hiking', 'reading', 'gaming'], 'form_settings' => [ 'validations' => [['validation' => 'required']], 'settings' => [['setting' => 'placeholder', 'value' => 'Pick hobbies…']], ], 'use_in_table' => true, 'table_settings' => [ ['setting' => 'filterable'], ['setting' => 'searchable'], ], 'infolist_settings' => [], 'customizable_type' => \App\Models\Employee::class, ]); // Query all fields for a model: $fields = Field::where('customizable_type', \App\Models\Employee::class) ->orderBy('sort') ->get(); // Soft-delete and restore: $field->delete(); Field::withTrashed()->find($field->id)->restore(); ``` -------------------------------- ### Troubleshoot Trait Methods Not Firing Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Ensure the Eloquent trait `HasCustomFields` is applied to your model and that `Field::where('customizable_type', …)` returns the expected rows. ```php use HasCustomFields; ``` ```php Field::where('customizable_type', …) ``` -------------------------------- ### Merge Custom Query Builder Constraints in Filament Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Use this static helper to merge custom query builder constraints with base constraints in a Filament resource. Specify fields to include or exclude. ```php static::mergeCustomTableQueryBuilderConstraints(array $base, array $include = [], array $exclude = []): array ``` -------------------------------- ### FieldType Enum for Supported Field Types Source: https://context7.com/aureuserp/custom-fields/llms.txt Backed enum (string) representing all supported field types. Provides a `default()` static returning `FieldType::Text`. Use `tryFrom()` for safe parsing with fallback. ```php use Webkul\CustomFields\Enums\FieldType; FieldType::Text->value; // 'text' FieldType::Textarea->value; // 'textarea' FieldType::Select->value; // 'select' FieldType::Checkbox->value; // 'checkbox' FieldType::Radio->value; // 'radio' FieldType::Toggle->value; // 'toggle' FieldType::CheckboxList->value;// 'checkbox_list' FieldType::DateTime->value; // 'datetime' FieldType::Editor->value; // 'editor' FieldType::Markdown->value; // 'markdown' FieldType::ColorPicker->value; // 'color' ``` ```php use Webkul\CustomFields\Enums\FieldType; // Safe parsing with fallback to default: $type = FieldType::tryFrom($rawString) ?? FieldType::default(); // FieldType::default() === FieldType::Text ``` -------------------------------- ### Integrate Custom Fields into Filament Resource Source: https://context7.com/aureuserp/custom-fields/llms.txt Add `HasCustomFields` to a Filament Resource to automatically merge custom form fields, table columns, filters, and infolist entries. Use `include` and `exclude` parameters to control which custom fields are merged. ```php use Filament\Resources\Resource; use Filament\Schemas\Schema; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Select; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; use Filament\Infolists\Infolist; use Webkul\CustomFields\Filament\Concerns\HasCustomFields; use App\Models\Employee; class EmployeeResource extends Resource { use HasCustomFields; protected static ?string $model = Employee::class; // --- Form --- public static function form(Schema $schema): Schema { return $schema->components( static::mergeCustomFormFields( [ TextInput::make('name')->required(), Select::make('department_id')->relationship('department', 'name'), ], include: [], // empty = all custom fields exclude: ['internal_notes'] // hide this field code from the form ) ); } // --- Table columns + filters --- public static function table(Table $table): Table { return $table ->columns( static::mergeCustomTableColumns( [TextColumn::make('name')->sortable()], include: ['hobbies', 'birth_year'] // only these two custom columns ) ) ->filters( static::mergeCustomTableFilters([]) // all filterable custom fields ) ->queryBuilderConstraints( static::mergeCustomTableQueryBuilderConstraints([]) ); } // --- Infolist --- public static function infolist(Infolist $infolist): Infolist { return $infolist->schema( static::mergeCustomInfolistEntries( [\Filament\Infolists\Components\TextEntry::make('name')], ) ); } } ``` -------------------------------- ### Manage Database Columns with CustomFieldsColumnManager Source: https://context7.com/aureuserp/custom-fields/llms.txt Manages underlying database columns for custom fields during creation, update, or deletion. All custom columns are created as nullable. DB type is inferred from field type and input type. ```php use Webkul\CustomFields\CustomFieldsColumnManager; use Webkul\CustomFields\Models\Field; // Create column when a new field definition is saved: $field = Field::create([ 'code' => 'birth_year', 'name' => 'Birth Year', 'type' => 'text', 'input_type' => 'integer', // → integer DB column 'customizable_type'=> \App\Models\Employee::class, ]); CustomFieldsColumnManager::createColumn($field); // ALTER TABLE employees ADD birth_year INTEGER NULL ``` ```php use Webkul\CustomFields\CustomFieldsColumnManager; use Webkul\CustomFields\Models\Field; // Update (re-creates if missing, e.g. after a soft-delete restore): CustomFieldsColumnManager::updateColumn($field); ``` ```php use Webkul\CustomFields\CustomFieldsColumnManager; use Webkul\CustomFields\Models\Field; // Drop the column when the field definition is deleted: CustomFieldsColumnManager::deleteColumn($field); // ALTER TABLE employees DROP COLUMN birth_year ``` ```php // Type mapping reference: // 'text' + input_type 'integer' → integer // 'text' + input_type 'numeric' → decimal // 'text' + other input_type → string // 'textarea' / 'editor' / 'markdown' → text // 'select' is_multiselect=true → json // 'select' is_multiselect=false → string // 'checkbox' / 'toggle' → boolean // 'checkbox_list' → json // 'datetime' → datetime // 'radio' / 'color' → string ``` -------------------------------- ### Merge Fillable Attributes with HasCustomFields Source: https://context7.com/aureuserp/custom-fields/llms.txt Use the public `mergeFillable` helper to deduplicate and merge attribute names into the model's `$fillable` list. This is called internally by `loadCustomFields()` but can be used ad-hoc. ```php $employee = new Employee(); $employee->mergeFillable(['custom_notes', 'custom_score']); // $employee->getFillable() now includes 'custom_notes' and 'custom_score' ``` -------------------------------- ### Register CustomFieldsPlugin in Filament Panel Source: https://context7.com/aureuserp/custom-fields/llms.txt Register the plugin in your Filament panel provider. Configure navigation and resource settings using fluent setters. ```php // app/Providers/Filament/AdminPanelProvider.php use Webkul\CustomFields\CustomFieldsPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ CustomFieldsPlugin::make() ->navigationGroup('Settings') ->navigationLabel('Custom Fields') ->navigationIcon('heroicon-o-puzzle-piece') ->navigationSort(50) ->navigationBadge(fn () => \Webkul\CustomFields\Models\Field::count()) ->navigationBadgeColor('primary') ->slug('admin/custom-fields') ->cluster(\App\Filament\Clusters\AdminTools::class) ->registerResource(true), // set false to disable admin CRUD entirely ]); } ``` -------------------------------- ### Merge Custom Table Columns in Filament Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Use this static helper to merge custom table columns with base columns in a Filament resource. Specify fields to include or exclude. ```php static::mergeCustomTableColumns(array $base, array $include = [], array $exclude = []): array ``` -------------------------------- ### Merge Custom Table Filters in Filament Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Use this static helper to merge custom table filters with base filters in a Filament resource. Specify fields to include or exclude. ```php static::mergeCustomTableFilters(array $base, array $include = [], array $exclude = []): array ``` -------------------------------- ### InputType Enum Values Source: https://context7.com/aureuserp/custom-fields/llms.txt Access the string value of `InputType` enum cases. Use `tryFrom` to convert a string to an enum instance, defaulting to `InputType::Text` if the string is not found. ```php use Webkul\CustomFields\Enums\InputType; InputType::Text->value; // 'text' InputType::Email->value; // 'email' InputType::Numeric->value; // 'numeric' → decimal DB column InputType::Integer->value; // 'integer' → integer DB column InputType::Password->value;// 'password' InputType::Tel->value; // 'tel' InputType::Url->value; // 'url' InputType::Color->value; // 'color' $inputType = InputType::tryFrom($rawString) ?? InputType::default(); // InputType::default() === InputType::Text ``` -------------------------------- ### Extend Filament Resource with HasCustomFields Trait Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Extend your Filament resource with the `HasCustomFields` trait and use the provided merge helpers to integrate custom fields into forms, tables, and filters. ```php use Filament\Resources\Resource; use Filament\Schemas\Schema; use Webkul\CustomFields\Filament\Concerns\HasCustomFields; class EmployeeResource extends Resource { use HasCustomFields; public static function form(Schema $schema): Schema { return $schema->components( static::mergeCustomFormFields([ // your base fields ]) ); } public static function table(Table $table): Table { return $table ->columns(static::mergeCustomTableColumns([ /* base */ ])) ->filters(static::mergeCustomTableFilters([ /* base */ ])); } ``` -------------------------------- ### Create Custom Fields Schema in Filament Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Instantiate and configure the CustomFields component for use in Filament forms. You can specify fields to include or exclude. ```php CustomFields::make(MyResource::class) ->include(['hobbies']) ->exclude(['internal_notes']) ->getSchema(); ``` -------------------------------- ### Build Standalone Custom Fields Table Columns Source: https://context7.com/aureuserp/custom-fields/llms.txt Generate Filament table column objects for custom fields using `CustomColumns::make()`. This builder automatically creates `TextColumn`, `IconColumn`, or `ColorColumn` based on field type for fields where `use_in_table` is true. You can filter columns using `include` and `exclude`. ```php use Webkul\CustomFields\Filament\Tables\Columns\CustomColumns; use App\Filament\Resources\EmployeeResource; $columns = CustomColumns::make(EmployeeResource::class)->getColumns(); // Selective columns: $columns = CustomColumns::make(EmployeeResource::class) ->include(['hobbies']) ->exclude(['internal_score']) ->getColumns(); // Merge into a Table definition manually: use Filament\Tables\Table; use Filament\Tables\Columns\TextColumn; public static function table(Table $table): Table { return $table->columns(array_merge( [TextColumn::make('name')], CustomColumns::make(static::class)->getColumns() )); } ``` -------------------------------- ### Mark Eloquent Model with HasCustomFields Trait Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Use the `HasCustomFields` trait in your Eloquent model to make custom fields mass-assignable and properly cast at runtime. ```php use Illuminate\Database\Eloquent\Model; use Webkul\CustomFields\Concerns\HasCustomFields; class Employee extends Model { use HasCustomFields; } ``` -------------------------------- ### Merge Custom Form Fields in Filament Source: https://github.com/aureuserp/custom-fields/blob/master/README.md Use this static helper to merge custom form fields with base fields in a Filament resource. Specify fields to include or exclude. ```php static::mergeCustomFormFields(array $base, array $include = [], array $exclude = []): array ``` -------------------------------- ### Use HasCustomFields Eloquent Trait Source: https://context7.com/aureuserp/custom-fields/llms.txt Apply the HasCustomFields trait to any Eloquent model. It automatically merges custom field codes into `$fillable` and applies casts. ```php use Illuminate\Database\Eloquent\Model; use Webkul\CustomFields\Concerns\HasCustomFields; class Employee extends Model { use HasCustomFields; protected $fillable = ['name', 'department_id']; // Custom field codes are merged in at runtime — no manual additions needed. } // After an admin creates a "hobbies" (checkbox_list) and "birth_year" (text/integer) field: $employee = Employee::create([ 'name' => 'Alice', 'department_id' => 1, 'hobbies' => ['chess', 'hiking'], // auto-fillable, cast to array 'birth_year' => 1990, // auto-fillable, cast to integer ]); $employee->hobbies; // ['chess', 'hiking'] $employee->birth_year; // 1990 // Override getCustomFields() to scope by tenant: class Employee extends Model { use HasCustomFields; protected function getCustomFields() { return parent::getCustomFields()->where('tenant_id', auth()->user()->tenant_id); } } ``` -------------------------------- ### Merge Casts with HasCustomFields Source: https://context7.com/aureuserp/custom-fields/llms.txt Use the `mergeCasts` method to merge standard Laravel casts or apply type-appropriate casts based on custom field types when passed a Collection of Field models. ```php // Pass an array (standard Laravel cast merge): $model->mergeCasts(['score' => 'integer', 'flags' => 'array']); // Pass a Field collection (called internally): $fields = \Webkul\CustomFields\Models\Field::where('customizable_type', Employee::class)->get(); $model->mergeCasts($fields); // → checkbox field 'is_remote' gets cast 'boolean' // → checkbox_list field 'skills' gets cast 'array' // → text field 'bio' gets cast 'string' ``` -------------------------------- ### Disable Admin CRUD for Custom Fields Plugin Source: https://github.com/aureuserp/custom-fields/blob/master/README.md To disable the admin CRUD entirely and only use the Eloquent trait and table-injection API, you can either use the `registerResource(false)` method or set `'register' => false` in the configuration file. ```php CustomFieldsPlugin::make()->registerResource(false), ``` ```php 'resource' => ['register' => false], ``` -------------------------------- ### Build Standalone Custom Fields Form Schema Source: https://context7.com/aureuserp/custom-fields/llms.txt Use `CustomFields::make()` to generate a custom fields form schema outside of a resource trait. This is useful for nested forms or custom Livewire components. You can filter fields using `include` and `exclude`. ```php use Webkul\CustomFields\Filament\Forms\Components\CustomFields; use App\Filament\Resources\EmployeeResource; // All fields for the resource: $schema = CustomFields::make(EmployeeResource::class)->getSchema(); // Whitelist specific field codes: $schema = CustomFields::make(EmployeeResource::class) ->include(['hobbies', 'certifications']) ->getSchema(); // Exclude sensitive fields: $schema = CustomFields::make(EmployeeResource::class) ->exclude(['internal_rating']) ->getSchema(); // Use inside a Filament form: use Filament\Schemas\Schema; public function form(Schema $schema): Schema { return $schema->components([ \Filament\Forms\Components\Section::make('Custom Attributes') ->schema( CustomFields::make(static::class)->getSchema() ), ]); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.