### Install Filament Table Select Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Install the package using Composer. This command requires version 2.0.7 or higher. ```bash composer require dvarilek/filament-table-select:^2.0.7 ``` -------------------------------- ### Globally Configure TableSelect Components Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Configure all TableSelect component instances globally by using the `configureUsing()` method in your application's Service Provider boot method. This example shows how to require selection confirmation. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; public function boot(): void { TableSelect::configureUsing(static function (TableSelect $tableSelect): void { $tableSelect->requiresSelectionConfirmation(); }); } ``` -------------------------------- ### Run Package Tests Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Execute the package's tests using the Composer command. ```bash composer test ``` -------------------------------- ### Use Pre-defined Table from Filament Resource Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Specify an existing Filament Resource to use for the selection table's location. This simplifies integration when a table is already defined. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; TableSelect::make('clients') ->relationship('clients', 'name') ->tableLocation(ClientResource::class) ``` -------------------------------- ### Configure Selected Option Badge Size Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use `optionSize()` to control the overall size of the selected option badges. Accepts values from `Filament\Support\Enums\ActionSize`. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Filament\Support\Enums\ActionSize; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->optionSize(ActionSize::Large) ]) ``` -------------------------------- ### Configure Selected Option Color Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use `optionColor()` to set a static color for all selected options. This is useful for consistent styling. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->optionColor('success') ]) ``` -------------------------------- ### Configure Selection Action Modal Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Customize the selection action's modal heading, icon, and slide-over behavior using the `selectionAction()` method. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Filament\Forms\Components\Actions\Action; TableSelect::make('clients') ->relationship('clients', 'name') ->selectionAction(function (Action $action) { return $action ->icon('heroicon-o-user-plus') ->modalHeading('Select Clients') ->slideOver(false); }) ``` -------------------------------- ### Configure Selected Option Icon Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use `optionIcon()` to set a static icon for all selected options. This can help visually distinguish selected items. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->optionIcon('heroicon-o-bell') ]) ``` -------------------------------- ### Customize Option Icon from Record Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use `getOptionIconFromRecordUsing()` to dynamically set the icon for selected options based on the record's properties. This provides granular control over visual representation. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->getOptionIconFromRecordUsing(function (Client $record) { return match ($record->status) { 'lead' => 'heroicon-o-light-bulb', 'closed' => 'heroicon-o-check-circle', 'lost' => 'heroicon-o-x-circle', 'active' => 'heroicon-o-bolt', default => 'heroicon-o-question-mark-circle', }; }) ]) ``` -------------------------------- ### Configure TableSelect with Min/Max Item Validation Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Set minimum and maximum selection limits using `minItems()` and `maxItems()`. If `maxItems(1)` is set, it behaves like radio button selection. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->minItems(1) ->maxItems(3) ]) ``` -------------------------------- ### Customize Option Label from Record Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use `getOptionLabelFromRecordUsing()` to dynamically format the display label of selected options using data from the Eloquent model instance. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->getOptionLabelFromRecordUsing(function (Client $record) { return "{$record->first_name} {$record->last_name} - {$record->status}"; }) ]) ``` -------------------------------- ### Configure Create Option Action for TableSelect Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use this snippet to enable and configure the action for creating new options directly within the TableSelect component's modal. You can define the form for new records, the logic for creating them, and customize the action itself. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; TableSelect::make('clients') ->relationship('clients', 'name') ->createOptionForm(ClientResource::form(...)) ->createOptionUsing(function (array $data) { // Create related record using... }) ->createOptionAction(function () { // Configure the action... }) ``` -------------------------------- ### Configure Selected Option Icon Size Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use `optionIconSize()` to adjust the size of icons displayed within the selected option badges. Accepts values from `Filament\Support\Enums\IconSize`. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Filament\Support\Enums\IconSize; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->optionIconSize(IconSize::Large) ]) ``` -------------------------------- ### Customize Option Color from Record Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use `getOptionColorFromRecordUsing()` to dynamically set the color of selected options based on the record's properties. This method allows access to the Eloquent model instance for conditional styling. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ->getOptionColorFromRecordUsing(function (Client $record) { return match ($record->status) { 'lead' => 'primary', 'closed' => 'success', 'lost' => 'gray', 'active' => 'danger', default => 'primary' }; }) ]) ``` -------------------------------- ### Replace Default Selection Table Livewire Component Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Substitute the default Livewire component for the selection table with a custom subclass. This is useful for integrating with other packages or adding custom Livewire traits. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; TableSelect::make('clients') ->relationship('clients', 'name') ->tableLocation(ClientResource::class) ->selectionTableLivewire(CustomSelectionTable::class); ``` -------------------------------- ### Configure Selection Table with Columns and Query Modification Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Define table columns and modify the underlying query within the selectionTable closure. This is essential for displaying data and filtering results. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; TableSelect::make('clients') ->relationship('clients', 'name') ->selectionTable(function (Table $table) { return $table ->heading('Active Clients') ->columns([ TextColumn::make('name') ]) ->modifyQueryUsing(fn (Builder $query) => $query->where('status', 'active')); }) ``` -------------------------------- ### Configure TableSelect for Multi-Selection Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Enable multi-selection by adding the `multiple()` method. This is suitable for `belongsToMany()` relationships, allowing users to select multiple records. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ->multiple() ]) ``` -------------------------------- ### Trigger Selection Modal on Input Click Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Enable opening the selection modal when the field is clicked directly using `triggerSelectionActionOnInputClick()` or by setting `shouldTriggerSelectionActionOnInputClick` to true in `selectionAction()`. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Filament\Forms\Components\Actions\Action; TableSelect::make('clients') ->relationship('clients', 'name') ->selectionAction(function (Action $action) { return $action ->icon('heroicon-o-user-plus') ->modalHeading('Select Clients') ->slideOver(false); }) ->triggerSelectionActionOnInputClick() ``` ```php ->selectionAction(shouldTriggerSelectionActionOnInputClick: true) ``` -------------------------------- ### Set Selection Action Position Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Control the alignment of the selection action button using `selectionActionAlignment()` or by passing an alignment parameter directly to `selectionAction()`. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Filament\Forms\Components\Actions\Action; use Filament\Support\Enums\Alignment; TableSelect::make('clients') ->relationship('clients', 'name') ->selectionAction(function (Action $action) { return $action ->icon('heroicon-o-user-plus') ->modalHeading('Select Clients') ->slideOver(false); }) ->selectionActionAlignment(Alignment::End) ``` ```php ->selectionAction(alignment: Alignment::Center) ``` -------------------------------- ### Keep Modal Open After Selection Confirmation Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Configure the modal to remain open after the selection has been confirmed. This is an alternative to the default behavior of closing the modal. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; TableSelect::make('clients') ->relationship('clients', 'name') ->requiresSelectionConfirmation() ->shouldCloseAfterSelection(false); ``` ```php ->requiresSelectionConfirmation(shouldCloseAfterSelection: false) ``` -------------------------------- ### Enable Selection Confirmation Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use this method to require explicit confirmation before updating the form component's state. This is useful for performance optimization when many models might be loaded. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; TableSelect::make('clients') ->relationship('clients', 'name') ->requiresSelectionConfirmation(); ``` -------------------------------- ### Change Confirmation Action Position Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Customize the position of the selection confirmation action within the modal. The default position is bottom left. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Dvarilek\FilamentTableSelect\Enums\SelectionModalActionPosition; TableSelect::make('clients') ->relationship('clients', 'name') ->requiresSelectionConfirmation() ->confirmationActionPosition(SelectionModalActionPosition::TOP_LEFT); ``` ```php use Dvarilek\FilamentTableSelect\Enums\SelectionModalActionPosition; ->requiresSelectionConfirmation(confirmationActionPosition: SelectionModalActionPosition::TOP_LEFT) ``` -------------------------------- ### Set Create Option Action Position in TableSelect Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Customize the position of the 'create option' action button within the TableSelect selection modal. By default, it appears in the top right corner. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Dvarilek\FilamentTableSelect\Enums\SelectionModalActionPosition; use Filament\Forms\Form; TableSelect::make('clients') ->relationship('clients', 'name') ->createOptionForm(fn (Form $form) => ClientResource::form($form)) ->createOptionActionPosition(SelectionModalActionPosition::TOP_LEFT) ``` -------------------------------- ### Pass Arguments to Selection Table Closure Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use selectionTableArguments to pass context, such as a branch ID obtained from a form field, into the selection table closure for dynamic query filtering. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; use Dvarilek\FilamentTableSelect\Components\Livewire\SelectionTable; use Illuminate\Database\Eloquent\Builder; use Filament\Tables\Table; use Filament\Forms\Get; TableSelect::make('employees') ->relationship('employees', 'name') ->multiple() ->selectionTableArguments(function (Get $get) { return [ // Suppose there is a branch_id field present in the schema 'branch_id' => $get('branch_id'), ]; }) ->tableLocation(EmployeeResource::class) ->selectionTable(fn (Table $table) => $table ->modifyQueryUsing(function (Builder $query, SelectionTable $livewire) { $branchId = $livewire->arguments['branch_id'] ?? null; if ($branchId) { $query->where('branch_id', $branchId); } return $query; }) ) ``` -------------------------------- ### Configure TableSelect for Single Selection Source: https://github.com/dvarilek/filament-table-select/blob/main/README.md Use this snippet to configure the TableSelect field for single-item selection. It requires setting up a relationship and specifying the title attribute for options. ```php use Dvarilek\FilamentTableSelect\Components\Form\TableSelect; $form ->schema([ TableSelect::make('clients') ->relationship('clients', 'name') ]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.