### Install Package via Composer (Bash) Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/2.installation.md Installs the `defstudio/filament-searchable-input` package using Composer. This command adds the package as a dependency to your project. ```bash composer require defstudio/filament-searchable-input ``` -------------------------------- ### Installing Filament Searchable Input via Composer Source: https://github.com/defstudio/filament-searchable-input/blob/main/FILAMENT_README.md Installs the `defstudio/filament-searchable-input` package using Composer. This command adds the package as a dependency to your project. ```Bash composer require defstudio/filament-searchable-input ``` -------------------------------- ### Publish Views (Artisan/Bash) Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/2.installation.md Publishes the package's views using the Laravel Artisan command. The `--tag` option specifically targets the views related to `filament-searchable-input`. ```bash php artisan vendor:publish --tag="filament-searchable-input-views" ``` -------------------------------- ### Installing Filament Searchable Input via Composer (Bash) Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Installs the Filament Searchable Input package using Composer. This is the standard method for adding the package to your Laravel/Filament project. ```bash composer require defstudio/filament-searchable-input ``` -------------------------------- ### Injecting Filament Utilities into SearchableInput Closures in PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/FILAMENT_README.md This snippet demonstrates the support for Filament utility injection within the closures provided to SearchableInput methods, specifically searchUsing. It shows examples of injecting common utilities such as $get, $set, the current state, component instance, form record, and form operation. ```php SearchableInput::make('description') ->searchUsing(function(string $search, array $options){ //options defined in ->options([...]) //... }) ->searchUsing(function(string $search, Get $get, Set $set){ //$get and $set utilities //... }) ->searchUsing(function(string $search, $state){ //current field state //... }) ->searchUsing(function(string $search, Component $component){ //current component instance //... }) ->searchUsing(function(string $search, ?Model $record){ //current form record //... }) ->searchUsing(function(string $search, string $operation){ //current form operation (create/update) //... }); ``` -------------------------------- ### Implementing Custom Search Function for SearchableInput Source: https://github.com/defstudio/filament-searchable-input/blob/main/FILAMENT_README.md Explains how to use the `searchUsing` method to define a custom closure that fetches search results dynamically based on user input. The closure receives the search string and should return an array of options (simple or associative). Note: The provided code block contains multiple return examples for illustration. ```PHP use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->searchUsing(function(string $search){ return Product::query() ->where('description', 'like', "%" . $search . "%") ->orWhere('code', 'like', "%" . $search . "%") ->limit(15) ->pluck('description') ->values() ->toArray(); // Or, an associative array as well... return Product::query() ->where('description', 'like', "%" . $search . "%") ->orWhere('code', 'like', "%" . $search . "%") ->limit(15) ->mapWithKeys(fn(Product $product) => [ $product->description => "[" . $product->code . "] " . $product->description" ]) ->toArray(); // Or, also, an array of complex items (see below) }) ]); } } ``` -------------------------------- ### Filament Utility Injection in SearchableInput Closures PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Illustrates how various Filament utilities and context variables, such as `$get`, `$set`, `$state`, `$component`, `$record`, and `$operation`, can be automatically injected into the closures provided to SearchableInput methods like `searchUsing`. ```php SearchableInput::make('description') ->searchUsing(function(string $search, array $options){ //options defined in ->options([...]) //... }) ->searchUsing(function(string $search, Get $get, Set $set){ //$get and $set utilities //... }) ->searchUsing(function(string $search, $state){ //current field state //... }) ->searchUsing(function(string $search, Component $component){ //current component instance //... }) ->searchUsing(function(string $search, ?Model $record){ //current form record //... }) ->searchUsing(function(string $search, string $operation){ //current form operation (create/update) //... }); ``` -------------------------------- ### Publishing Filament Searchable Input Views (Bash) Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Optionally publishes the package's views to your application, allowing for customization of the input's appearance. ```bash php artisan vendor:publish --tag="filament-searchable-input-views" ``` -------------------------------- ### Publishing Filament Searchable Input Views Source: https://github.com/defstudio/filament-searchable-input/blob/main/FILAMENT_README.md Publishes the view files for the Filament Searchable Input component. This is optional and allows customization of the component's appearance. ```Bash php artisan vendor:publish --tag="filament-searchable-input-views" ``` -------------------------------- ### Using SearchableInput with Static Options (Value-Label Pairs) Source: https://github.com/defstudio/filament-searchable-input/blob/main/FILAMENT_README.md Shows how to provide options to `SearchableInput` using an associative array where keys are the values inserted into the input and values are the labels displayed in the dropdown. ```PHP use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->options([ 'Lorem ipsum dolor' => '[A001] Lorem ipsum dolor.', 'Aspernatur labore qui fugiat' => '[A001] Aspernatur labore qui fugiat.', 'Dolores tempora libero assumenda' => '[A002] Dolores tempora libero assumenda.', 'Qui rem voluptas officiis ut non' => '[A003] Qui rem voluptas officiis ut non.', //.. ]) ]); } } ``` -------------------------------- ### Using SearchableInput with Simple Options Array (PHP) Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Demonstrates basic usage of the `SearchableInput` component in a Filament form schema, providing a simple array of strings as static options for the dropdown. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->options([ 'Lorem ipsum dolor', 'Aspernatur labore qui fugiat', 'Dolores tempora libero assumenda', 'Qui rem voluptas officiis ut non', //.. ]) ]); } } ``` -------------------------------- ### Using SearchableInput with Static Options (Simple Array) Source: https://github.com/defstudio/filament-searchable-input/blob/main/FILAMENT_README.md Demonstrates how to use the `SearchableInput` component in a Filament form schema by providing a simple array of string options. The component will filter these options as the user types. ```PHP use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->options([ 'Lorem ipsum dolor', 'Aspernatur labore qui fugiat', 'Dolores tempora libero assumenda', 'Qui rem voluptas officiis ut non', //.. ]) ]); } } ``` -------------------------------- ### Using SearchableInput with Value-Label Options (PHP) Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Shows how to configure `SearchableInput` with an associative array where keys are the values inserted into the input and values are the labels displayed in the dropdown. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->options([ 'Lorem ipsum dolor' => '[A001] Lorem ipsum dolor.', 'Aspernatur labore qui fugiat' => '[A001] Aspernatur labore qui fugiat.', 'Dolores tempora libero assumenda' => '[A002] Dolores tempora libero assumenda.', 'Qui rem voluptas officiis ut non' => '[A003] Qui rem voluptas officiis ut non.', //.. ]) ]); } } ``` -------------------------------- ### Using SearchableInput with Simple Options PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/3.usage.md Demonstrates a basic implementation of the SearchableInput component in a Filament form, providing a simple array of string options that the user can select from. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->options([ 'Lorem ipsum dolor', 'Aspernatur labore qui fugiat', 'Dolores tempora libero assumenda', 'Qui rem voluptas officiis ut non', //.. ]) ]); } } ``` -------------------------------- ### Using searchUsing with Filament Utilities (PHP) Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/3.usage.md The `searchUsing` method of `SearchableInput` allows injecting various Filament utilities and contextual data such as the current state, component instance, form record, and operation type (create/update) as arguments. ```php SearchableInput::make('description') ->searchUsing(function(string $search, array $options){ //options defined in ->options([...]) //... }) ->searchUsing(function(string $search, Get $get, Set $set){ //$get and $set utilities //... }) ->searchUsing(function(string $search, $state){ //current field state //... }) ->searchUsing(function(string $search, Component $component){ //current component instance //... }) ->searchUsing(function(string $search, ?Model $record){ //current form record //... }) ->searchUsing(function(string $search, string $operation){ //current form operation (create/update) //... }); ``` -------------------------------- ### Implementing Custom Search Returning Simple Array (PHP) Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Illustrates using the `searchUsing` method with a closure that performs a database query based on user input and returns a simple array of strings (values) for the dropdown. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->searchUsing(function(string $search){ return Product::query() ->where('description', 'like', "%"$search"%") ->orWhere('code', 'like', "%"$search"%") ->limit(15) ->pluck('description') ->values() ->toArray(); // Or, an associative array as well... // return Product::query() // ->where('description', 'like', "%"$search"%") // ->orWhere('code', 'like', "%"$search"%") // ->limit(15) // ->mapWithKeys(fn(Product $product) => [ // $product->description => "[$product->code] $product->description" // ]) // ->toArray(); // Or, also, an array of complex items (see below) }) ]); } } ``` -------------------------------- ### Using SearchableInput with Value-Label Options PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/3.usage.md Shows how to configure the SearchableInput component using an associative array for options, where keys represent the actual value stored and values represent the display label shown in the dropdown. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->options([ 'Lorem ipsum dolor' => '[A001] Lorem ipsum dolor.', 'Aspernatur labore qui fugiat' => '[A001] Aspernatur labore qui fugiat.', 'Dolores tempora libero assumenda' => '[A002] Dolores tempora libero assumenda.', 'Qui rem voluptas officiis ut non' => '[A003] Qui rem voluptas officiis ut non.', //.. ]) ]); } } ``` -------------------------------- ### Implementing Custom Search with searchUsing PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/3.usage.md Illustrates how to define a custom search function for the SearchableInput using the `searchUsing` method. The provided closure receives the user's input and should return an array of options, typically by querying a database. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->searchUsing(function(string $search){ return Product::query() ->where('description', 'like', "%" . $search . "%") ->orWhere('code', 'like', "%" . $search . "%") ->limit(15) ->pluck('description') ->values() ->toArray(); // Or, an associative array as well... return Product::query() ->where('description', 'like', "%" . $search . "%") ->orWhere('code', 'like', "%" . $search . "%") ->limit(15) ->mapWithKeys(fn(Product $product) => [ $product->description => "[$product->code] $product->description" ]) ->toArray(); // Or, also, an array of complex items (see below) }) ]); } } ``` -------------------------------- ### Implementing Custom Search Returning Associative Array (PHP) Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Shows an alternative implementation for `searchUsing` where the closure returns an associative array (value-label pairs) from a database query, providing more control over display text. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->searchUsing(function(string $search){ // return Product::query() // ->where('description', 'like', "%"$search"%") // ->orWhere('code', 'like', "%"$search"%") // ->limit(15) // ->pluck('description') // ->values() // ->toArray(); // Or, an associative array as well... return Product::query() ->where('description', 'like', "%"$search"%") ->orWhere('code', 'like', "%"$search"%") ->limit(15) ->mapWithKeys(fn(Product $product) => [ $product->description => "[$product->code] $product->description" ]) ->toArray(); // Or, also, an array of complex items (see below) }) ]); } } ``` -------------------------------- ### Defining Static Options for SearchableInput in PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/0.index.md This snippet demonstrates how to create a `SearchableInput` field named 'description' and populate its autocomplete options using a static PHP array. This method is suitable for providing a fixed list of predefined choices directly within the form definition. ```php SearchableInput::make('description') ->options([ 'Lorem ipsum dolor', 'Aspernatur labore qui fugiat', 'Dolores tempora libero assumenda', 'Qui rem voluptas officiis ut non', //.. ]) ``` -------------------------------- ### Handling Complex Search Results and Item Selection PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/docs/3.usage.md Explains how to return complex items (like SearchResult DTOs) from the `searchUsing` closure to include metadata. It also shows how to use the `onItemSelected` method to access the value, label, and custom data of the selected item. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; use DefStudio\SearchableInput\DTO\SearchResult; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->searchUsing(function(string $search){ return Product::query() ->where('description', 'like', "%" . $search . "%") ->limit(15) ->map(fn(Product $product) => SearchResult::make($product->description, "[$product->code] $product->description") ->withData('product_id', $product->id) ->withData('product_code', $product->code) ) ->toArray(); }) ->onItemSelected(function(SearchResult $item){ $item->value(); $item->label(); $item->get('product_id'); $item->get('product_code'); }), ]); } } ``` -------------------------------- ### Using SearchableInput with Complex Items in Filament PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/README.md Demonstrates how to configure the SearchableInput component to return complex items (arrays) as search results using the SearchResult DTO. It shows how to query data, map results to SearchResult objects including custom metadata with `withData()`, and access this metadata within the `onItemSelected()` callback. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; use DefStudio\SearchableInput\DTO\SearchResult; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->searchUsing(function(string $search){ return Product::query() ->where('description', 'like', "%" . $search . "%") ->limit(15) ->map(fn(Product $product) => SearchResult::make($product->description, "[" . $product->code . "] " . $product->description) ->withData('product_id', $product->id) ->withData('product_code', $product->code) ) ->toArray(); }) ->onItemSelected(function(SearchResult $item){ $item->value(); $item->label(); $item->get('product_id'); $item->get('product_code'); }), ]); } } ``` -------------------------------- ### Using Complex Search Results with SearchableInput in PHP Source: https://github.com/defstudio/filament-searchable-input/blob/main/FILAMENT_README.md This snippet shows how to configure Filament's SearchableInput to return complex items (SearchResult objects with attached data) from the searchUsing closure. It also demonstrates how to access the value, label, and custom data associated with the selected item within the onItemSelected closure. ```php use DefStudio\SearchableInput\Forms\Components\SearchableInput; use DefStudio\SearchableInput\DTO\SearchResult; class ProductResource { public static function form(Form $form): Form { return $form->schema([ SearchableInput::make('description') ->searchUsing(function(string $search){ return Product::query() ->where('description', 'like', "%$search%") ->limit(15) ->map(fn(Product $product) => SearchResult::make($product->description, "[$product->code] $product->description") ->withData('product_id', $product->id) ->withData('product_code', $product->code) ) ->toArray() }) ->onItemSelected(function(SearchResult $item){ $item->value(); $item->label(); $item->get('product_id'); $item->get('product_code'); }), ]); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.