### Quick Start for New Laravel Projects Source: https://filamentphp.com/docs/3.x/forms/installation Run these commands in a new Laravel project to install Livewire, Alpine.js, and Tailwind CSS along with Filament's Form Builder. This will scaffold necessary files. ```bash php artisan filament:install --scaffold --forms ``` ```bash npm install ``` ```bash npm run dev ``` -------------------------------- ### Add multiple example rows to ImportColumn Source: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import Use the `examples()` method to provide multiple example values that appear as separate rows in the downloadable example CSV file. ```php use Filament\Actions\Imports\ImportColumn; ImportColumn::make('sku') ->examples(['ABC123', 'DEF456']) ``` -------------------------------- ### Add single example value to ImportColumn Source: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import Use the `example()` method to provide a single example value that appears in the downloadable example CSV file. ```php use Filament\Actions\Imports\ImportColumn; ImportColumn::make('sku') ->example('ABC123') ``` -------------------------------- ### Install Table Builder assets via Artisan Source: https://filamentphp.com/docs/3.x/tables/installation Run this command to install the necessary assets for the Filament Table Builder. ```bash php artisan filament:install --tables ``` -------------------------------- ### Install Filament for New Laravel Projects Source: https://filamentphp.com/docs/3.x/actions Run these commands in a new Laravel project to install Livewire, Alpine.js, Tailwind CSS, and scaffold Filament with actions. ```bash php artisan filament:install --scaffold --actions ``` ```bash npm install ``` ```bash npm run dev ``` -------------------------------- ### Install Filament Infolists package assets Source: https://filamentphp.com/docs/3.x/infolists/installation Run this Artisan command to install the Infolists package assets in an existing Laravel project. ```bash php artisan filament:install --infolists ``` -------------------------------- ### Install Filament and Frontend Dependencies for New Laravel Projects Source: https://filamentphp.com/docs/3.x/forms Run these commands in a new Laravel project to install Filament with scaffolding, Livewire, Alpine.js, and Tailwind CSS, then compile assets. ```bash php artisan filament:install --scaffold --forms ``` ```bash npm install ``` ```bash npm run dev ``` -------------------------------- ### Install Filament for New Laravel Projects Source: https://filamentphp.com/docs/3.x/tables These commands install Livewire, Alpine.js, and Tailwind CSS, scaffolding a new Filament project with table support. Only run this in a new Laravel project as it overwrites existing files. ```bash php artisan filament:install --scaffold --tables npm install npm run dev ``` -------------------------------- ### Filament theme setup instructions Source: https://filamentphp.com/docs/3.x/panels/themes Output from the `make:filament-theme` command detailing the next steps to register and compile the theme. ```text ⇂ First, add a new item to the `input` array of `vite.config.js`: `resources/css/filament/admin/theme.css` ⇂ Next, register the theme in the admin panel provider using `->viteTheme('resources/css/filament/admin/theme.css')` ⇂ Finally, run `npm run build` to compile the theme ``` -------------------------------- ### Install Filament Widgets package assets Source: https://filamentphp.com/docs/3.x/widgets/installation Run this command in an existing Laravel project to install the Widgets package assets. ```bash php artisan filament:install --widgets ``` -------------------------------- ### Set Component Starting Column in Filament Grid (PHP) Source: https://filamentphp.com/docs/3.x/infolists/layout/grid Use the `columnStart()` method on a component within a Filament `Grid` to specify its starting column. This method accepts an integer for a fixed start or an associative array for responsive breakpoint-specific starting columns. ```php use Filament\Infolists\Components\Grid; use Filament\Infolists\Components\TextEntry; Grid::make() ->columns([ 'sm' => 3, 'xl' => 6, '2xl' => 8, ]) ->schema([ TextEntry::make('name') ->columnStart([ 'sm' => 2, 'xl' => 3, '2xl' => 4, ]), // ... ]) ``` -------------------------------- ### Install Filament Panel Builder Source: https://filamentphp.com/docs/3.x/panels Run these commands in your Laravel project directory to install the Filament Panel Builder and register its service provider. ```bash composer require filament/filament:"^3.3" -W php artisan filament:install --panels ``` -------------------------------- ### Default resolveRecord() method with commented firstOrNew example Source: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import Shows the default importer structure with an example of using `firstOrNew()` to update existing records by matching on a column. Uncomment and customize the column name to enable update-or-create behavior. ```php use App\Models\Product; public function resolveRecord(): ?Product { // return Product::firstOrNew([ // // Update existing records, matching them by `$this->data['column_name']` // 'email' => $this->data['email'], // ]); return new Product(); } ``` -------------------------------- ### Install Filament Table Builder Assets for Existing Projects Source: https://filamentphp.com/docs/3.x/tables Run this command to install the necessary assets for the Table Builder in an existing Laravel project. ```bash php artisan filament:install --tables ``` -------------------------------- ### Install Filament Form Builder assets Source: https://filamentphp.com/docs/3.x/forms/installation Run this command in an existing Laravel project to install Form Builder assets. ```bash php artisan filament:install --forms ``` -------------------------------- ### Publish migrations and run database migrations Source: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/export Required setup for Filament actions. Run these commands to publish migration files and apply them to your database. ```bash php artisan vendor:publish --tag=filament-actions-migrations ``` ```bash php artisan migrate ``` -------------------------------- ### Set up new Laravel project with Filament Actions Source: https://filamentphp.com/docs/3.x/actions/installation Install Livewire, Alpine.js, and Tailwind CSS scaffolding in a new Laravel project. Only run these commands in a fresh project as they overwrite existing files. ```bash php artisan filament:install --scaffold --actions npm install npm run dev ``` -------------------------------- ### Install Filament Actions package assets Source: https://filamentphp.com/docs/3.x/actions/installation Run this Artisan command to install the necessary assets for the Filament Actions package in an existing Laravel project. ```bash php artisan filament:install --actions ``` -------------------------------- ### Install Filament Panel Builder with Composer Source: https://filamentphp.com/docs/3.x/panels/installation Run these commands in your Laravel project directory to install Filament 3.3 and register the panel service provider. ```bash composer require filament/filament:"^3.3" -W php artisan filament:install --panels ``` -------------------------------- ### Scaffold Filament Infolist Builder in new projects Source: https://filamentphp.com/docs/3.x/infolists/installation Commands to install Livewire, Alpine.js, and Tailwind CSS along with Filament infolists. Only use this in new Laravel projects as it overwrites existing files. ```bash php artisan filament:install --scaffold --infolists npm install npm run dev ``` -------------------------------- ### Scaffold Table Builder in new Laravel projects Source: https://filamentphp.com/docs/3.x/tables/installation Installs Livewire, Alpine.js, and Tailwind CSS automatically. This command should only be used in new projects as it overwrites existing files. ```bash php artisan filament:install --scaffold --tables npm install npm run dev ``` -------------------------------- ### Install esbuild via NPM Source: https://filamentphp.com/docs/3.x/support/assets Install esbuild as a development dependency for compiling JavaScript and Alpine components. ```bash npm install esbuild --save-dev ``` -------------------------------- ### Set Default Active Step in Wizard Source: https://filamentphp.com/docs/3.x/forms/layout/wizard Configure the wizard to start on a specific step by using the `startOnStep()` method with the step index. ```php use Filament\Forms\Components\Wizard; Wizard::make([ // ... ])->startOnStep(2) ``` -------------------------------- ### Install Filament Infolist Builder via Composer Source: https://filamentphp.com/docs/3.x/infolists/installation Command to require the Infolist Builder package in an existing Laravel application. ```bash composer require filament/infolists:"^3.3" -W ``` -------------------------------- ### Heading Component Usage Example Source: https://filamentphp.com/docs/3.x/support/plugins/build-a-standalone-plugin Demonstrates how to instantiate and configure the Heading component within a Filament project, specifying the level, content, and color. ```php use Awcodes\Headings\Heading; Heading::make(2) ->content('Product Information') ->color(Color::Lime), ``` -------------------------------- ### Customize example CSV column header Source: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import Use the `exampleHeader()` method to set a custom header name for a column in the example CSV file. ```php use Filament\Actions\Imports\ImportColumn; ImportColumn::make('sku') ->exampleHeader('SKU') ``` -------------------------------- ### Basic Filament Line Chart Widget Example Source: https://filamentphp.com/docs/3.x/widgets/charts This example demonstrates a basic line chart widget, defining its heading, data, and type. The `getData()` method returns datasets and labels compatible with Chart.js. ```php [ [ 'label' => 'Blog posts created', 'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89], ], ], 'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], ]; } protected function getType(): string { return 'line'; } } ``` -------------------------------- ### Blade Input Wrapper Usage Source: https://filamentphp.com/docs/3.x/support/blade-components/input-wrapper This Blade example demonstrates how to wrap Filament input and select components with the `x-filament::input.wrapper` component to apply styling and additional elements. ```blade ``` -------------------------------- ### Filament theme setup instructions for Tailwind v4 Source: https://filamentphp.com/docs/3.x/panels/themes Instructions provided when Tailwind v4 is detected, including a command to compile the theme using Tailwind v3 CLI. ```text ⇂ It looks like you have Tailwind v4 installed. Filament uses Tailwind v3. You should downgrade your project and re-run this command with `--force`, or use the following command to compile the theme with the Tailwind v3 CLI: ⇂ npx tailwindcss@3 --input ./resources/css/filament/admin/theme.css --output ./public/css/filament/admin/theme.css --config ./resources/css/filament/admin/tailwind.config.js --minify ⇂ Make sure to register the theme in the admin panel provider using `->theme(asset('css/filament/admin/theme.css'))` ``` -------------------------------- ### Example Data Structure for $get() in Repeater (PHP Array) Source: https://filamentphp.com/docs/3.x/forms/fields/repeater This PHP array demonstrates the data structure for a form containing a 'client_id' and a nested repeater, used to explain '$get()' scoping. ```php [ 'client_id' => 1, 'repeater' => [ 'item1' => [ 'service_id' => 2, ], ], ] ``` -------------------------------- ### Retrieve Enabled CheckboxList Options Source: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list Use `getEnabledOptions()` to get a list of options that are not disabled, useful for validation purposes. This example also shows how to set the component's value to only enabled options. ```php use Filament\Forms\Components\CheckboxList; CheckboxList::make('technologies') ->options([ 'tailwind' => 'Tailwind CSS', 'alpine' => 'Alpine.js', 'laravel' => 'Laravel', 'livewire' => 'Laravel Livewire', 'heroicons' => 'SVG icons', ]) ->disableOptionWhen(fn (string $value): bool => $value === 'heroicons') ->in(fn (CheckboxList $component): array => array_keys($component->getEnabledOptions())) ``` -------------------------------- ### PHP: Authenticating User in Test Case Setup Source: https://filamentphp.com/docs/3.x/panels/testing Configures the test environment to authenticate a newly created user before each test, ensuring access to app functionalities. ```php protected function setUp(): void { parent::setUp(); $this->actingAs(User::factory()->create()); } ``` -------------------------------- ### Register cluster discovery in panel configuration Source: https://filamentphp.com/docs/3.x/panels/clusters Configure the panel to discover cluster classes using discoverClusters() alongside resource and page discovery. Required setup in the panel configuration method. ```php public function panel(Panel $panel): Panel { return $panel // ... ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources') ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages') ->discoverClusters(in: app_path('Filament/Clusters'), for: 'App\\Filament\\Clusters'); } ``` -------------------------------- ### Example Data Structure for Filament Builder Parent Field Access Source: https://filamentphp.com/docs/3.x/forms/fields/builder Illustrates a typical data structure for a Filament form containing a Builder field, used to explain relative path access with `$get()`. ```php [ 'client_id' => 1, 'builder' => [ 'item1' => [ 'service_id' => 2, ], ], ] ``` -------------------------------- ### Set current panel for testing in Filament Source: https://filamentphp.com/docs/3.x/panels/testing Use Filament::setCurrentPanel() in setUp() or at the start of a test to specify which panel to test when working with multiple panels. Required when testing Livewire components that don't make HTTP requests. ```php use Filament\Facades\Filament; Filament::setCurrentPanel( Filament::getPanel('app'), // Where `app` is the ID of the panel you want to test. ); ``` -------------------------------- ### Automated Filament v3 Upgrade Source: https://filamentphp.com/docs/3.x/actions/upgrade-guide Run the automated upgrade script to upgrade your Filament application to v3. Execute the filament-v3 command after installing the upgrade package, then run php artisan filament:install to finalize the installation. ```bash composer require filament/upgrade:"^3.2" -W --dev vendor/bin/filament-v3 ``` -------------------------------- ### Install Chart.js plugins via NPM Source: https://filamentphp.com/docs/3.x/widgets/charts Add external functionality to Chart.js by installing packages as development dependencies. ```bash npm install chartjs-plugin-datalabels --save-dev ``` -------------------------------- ### Implement a Custom Filament Billing Provider Source: https://filamentphp.com/docs/3.x/panels/tenancy Create a class that implements `Filament\Billing\Providers\Contracts\Provider` to define custom billing logic. This example uses a callback for the route action and a middleware for subscription checking. ```php use App\Http\Middleware\RedirectIfUserNotSubscribed; use Filament\Billing\Providers\Contracts\Provider; use Illuminate\Http\RedirectResponse; class ExampleBillingProvider implements Provider { public function getRouteAction(): string { return function (): RedirectResponse { return redirect('https://billing.example.com'); }; } public function getSubscribedMiddleware(): string { return RedirectIfUserNotSubscribed::class; } } ``` -------------------------------- ### Validate field doesn't start with value in Filament Source: https://filamentphp.com/docs/3.x/forms/validation Validates that the field does not start with any of the given values. Accepts an array of strings. ```php Field::make('name')->doesntStartWith(['admin']) ``` -------------------------------- ### Create multistep wizard modal with steps Source: https://filamentphp.com/docs/3.x/actions/modals Use steps() instead of form() to create a wizard-style modal with multiple sequential steps. Each Step contains a schema of form components and optional descriptions. ```php use Filament\Forms\Components\MarkdownEditor; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Forms\Components\Wizard\Step; Action::make('create') ->steps([ Step::make('Name') ->description('Give the category a unique name') ->schema([ TextInput::make('name') ->required() ->live() ->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state))), TextInput::make('slug') ->disabled() ->required() ->unique(Category::class, 'slug'), ]) ->columns(2), Step::make('Description') ->description('Add some extra details') ->schema([ MarkdownEditor::make('description'), ]), Step::make('Visibility') ->description('Control who can view it') ->schema([ Toggle::make('is_visible') ->label('Visible to customers.') ->default(true), ]), ]) ``` -------------------------------- ### Finalize Filament v3 Installation Source: https://filamentphp.com/docs/3.x/panels/upgrade-guide Run this command after the upgrade process to finalize the Filament v3 installation for new projects. ```php php artisan filament:install ``` -------------------------------- ### Configure tenant domain routing with full domain Source: https://filamentphp.com/docs/3.x/panels/tenancy Set up full-domain tenant routing where the entire domain is resolved from a tenant attribute. The domain attribute should contain a valid domain host like example.com or subdomain.example.com. ```php use App\Models\Team; use Filament\Panel; public function panel(Panel $panel): Panel { return $panel // ... ->tenant(Team::class, slugAttribute: 'domain') ->tenantDomain('{tenant:domain}'); } ``` -------------------------------- ### Configure Grid Component Column Start with Breakpoints Source: https://filamentphp.com/docs/3.x/forms/layout/grid Use columnStart() with a breakpoint array to position a TextInput at different columns across responsive breakpoints. The grid itself is configured with varying column counts per breakpoint. ```php use Filament\Forms\Components\Section; Section::make() ->columns([ 'sm' => 3, 'xl' => 6, '2xl' => 8, ]) ->schema([ TextInput::make('name') ->columnStart([ 'sm' => 2, 'xl' => 3, '2xl' => 4, ]), // ... ]) ``` -------------------------------- ### Install Filament Actions package with Composer Source: https://filamentphp.com/docs/3.x/actions/installation Require the Actions package using Composer with the -W flag to resolve dependencies. Run this in an existing Laravel project with Livewire and Tailwind already configured. ```bash composer require filament/actions:"^3.3" -W ``` -------------------------------- ### Install Laravel Trend Package Source: https://filamentphp.com/docs/3.x/panels/getting-started Install the flowframe/laravel-trend package via Composer to easily populate chart data from Eloquent models. ```bash composer require flowframe/laravel-trend ``` -------------------------------- ### Full Livewire Component for Form Creation Source: https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component This comprehensive example shows how to set up a Livewire component with a Filament form, including interface implementation, data property, form schema definition, initialization, and a basic submission handler. ```php form->fill(); } public function form(Form $form): Form { return $form ->schema([ TextInput::make('title') ->required(), MarkdownEditor::make('content'), // ... ]) ->statePath('data'); } public function create(): void { dd($this->form->getState()); } public function render(): View { return view('livewire.create-post'); } } ``` -------------------------------- ### Install Filament Notifications assets via Artisan Source: https://filamentphp.com/docs/3.x/notifications/installation Run this command to install the necessary assets for the Notifications package in your Laravel project. ```bash php artisan filament:install --notifications ``` -------------------------------- ### Generate resource with model, migration, and factory Source: https://filamentphp.com/docs/3.x/panels/resources/getting-started Create resource along with the Eloquent model, database migration, and model factory in a single command using multiple flags. ```bash php artisan make:filament-resource Customer --model --migration --factory ``` -------------------------------- ### Manual Configuration and Cleanup Source: https://filamentphp.com/docs/3.x/notifications/upgrade-guide Publish the new unified configuration file and remove the deprecated notifications configuration file. ```bash php artisan vendor:publish --tag=filament-config --force rm config/notifications.php ``` -------------------------------- ### Install Filament Spark billing provider Source: https://filamentphp.com/docs/3.x/panels/tenancy Install the necessary package via Composer to integrate Laravel Spark billing into your Filament panel. ```bash composer require filament/spark-billing-provider ``` -------------------------------- ### Initialize Form with Existing Model Data Source: https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component Demonstrates how to pre-fill a Filament form in the `mount()` method using data from an existing Eloquent model for editing purposes. ```php use App\Models\Post; public function mount(Post $post): void { $this->form->fill($post->attributesToArray()); } ``` -------------------------------- ### Create a Basic Filament Form Wizard Source: https://filamentphp.com/docs/3.x/forms/layout/wizard Define a multi-step form wizard using `Wizard::make()` and `Wizard\Step::make()` to organize form components into distinct stages. ```php use Filament\Forms\Components\Wizard; Wizard::make([ Wizard\Step::make('Order') ->schema([ // ... ]), Wizard\Step::make('Delivery') ->schema([ // ... ]), Wizard\Step::make('Billing') ->schema([ // ... ]), ]) ``` -------------------------------- ### Injecting field state using Get in Filament Forms Source: https://filamentphp.com/docs/3.x/forms/advanced Use the $get parameter to retrieve the current value of another field within a callback. ```php use Filament\Forms\Get; function (Get $get) { $email = $get('email'); // Store the value of the `email` field in the `$email` variable. //... } ``` -------------------------------- ### Create Stats Overview Widget Source: https://filamentphp.com/docs/3.x/widgets/stats-overview Generate a new stats overview widget using the Artisan command. ```bash php artisan make:filament-widget StatsOverview --stats-overview ``` -------------------------------- ### Create Infolist Entries Source: https://filamentphp.com/docs/3.x/infolists/entries/getting-started Instantiate entries using the make method. Dot notation allows access to attributes on related models. ```php use Filament\Infolists\Components\TextEntry; TextEntry::make('title') TextEntry::make('author.name') ``` -------------------------------- ### Scaffold New Laravel Project with Filament Notifications Source: https://filamentphp.com/docs/3.x/notifications/installation Quick-start commands for a new Laravel project that install Livewire, Alpine.js, Tailwind CSS, and Filament Notifications with scaffolding. Only use in a fresh Laravel project as these commands overwrite existing files. ```bash php artisan filament:install --scaffold --notifications npm install npm run dev ``` -------------------------------- ### Run Filament v3 automated upgrade script Source: https://filamentphp.com/docs/3.x/forms/upgrade-guide Execute the automated upgrade script to handle most breaking changes. Run this after installing the upgrade package, then finalize with php artisan filament:install. ```bash composer require filament/upgrade:"^3.2" -W --dev vendor/bin/filament-v3 ``` -------------------------------- ### Generate resource with View page Source: https://filamentphp.com/docs/3.x/panels/resources/getting-started Create resource including a View page in addition to the default List, Create, and Edit pages for displaying record details. ```bash php artisan make:filament-resource Customer --view ``` -------------------------------- ### Install Tailwind CSS v3 and plugins Source: https://filamentphp.com/docs/3.x/actions/installation Use this npm command to install Tailwind CSS v3 along with required plugins like Tailwind Forms, Typography, PostCSS, PostCSS Nesting, and Autoprefixer. ```bash npm install tailwindcss@3 @tailwindcss/forms @tailwindcss/typography postcss postcss-nesting autoprefixer --save-dev ``` -------------------------------- ### Implement Get and Set Methods for MoneyCast Source: https://filamentphp.com/docs/3.x/panels/getting-started Update the `get` and `set` methods in `MoneyCast.php` to convert integer currency values from the database to floats for retrieval and back to integers for storage, preventing precision issues. ```php public function get($model, string $key, $value, array $attributes): float { // Transform the integer stored in the database into a float. return round(floatval($value) / 100, precision: 2); } public function set($model, string $key, $value, array $attributes): float { // Transform the float into an integer for storage. return round(floatval($value) * 100); } ``` -------------------------------- ### Configure storage disk and visibility Source: https://filamentphp.com/docs/3.x/tables/columns/image Specify a custom filesystem disk or set visibility to private to generate temporary URLs. ```php use Filament\Tables\Columns\ImageColumn; ImageColumn::make('header_image') ->disk('s3') ``` ```php use Filament\Tables\Columns\ImageColumn; ImageColumn::make('header_image') ->visibility('private') ``` -------------------------------- ### Install Filament Notifications Package via Composer Source: https://filamentphp.com/docs/3.x/notifications/installation Installs the Filament Notifications package version 3.3 or higher with the -W flag to resolve dependencies. Run this in an existing Laravel project with Livewire, Alpine.js, and Tailwind CSS already configured. ```bash composer require filament/notifications:"^3.3" -W ``` -------------------------------- ### Define Wizard Steps for Filament Record Creation Source: https://filamentphp.com/docs/3.x/panels/resources/creating-records Implement the `getSteps()` method to define the individual steps of a Filament wizard, each containing a description and an array of form components for data input. ```php use Filament\Forms\Components\MarkdownEditor; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Forms\Components\Wizard\Step; protected function getSteps(): array { return [ Step::make('Name') ->description('Give the category a clear and unique name') ->schema([ TextInput::make('name') ->required() ->live() ->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state))), TextInput::make('slug') ->disabled() ->required() ->unique(Category::class, 'slug', fn ($record) => $record), ]), Step::make('Description') ->description('Add some extra details') ->schema([ MarkdownEditor::make('description') ->columnSpan('full'), ]), Step::make('Visibility') ->description('Control who can view it') ->schema([ Toggle::make('is_visible') ->label('Visible to customers.') ->default(true), ]), ]; } ``` -------------------------------- ### Create a Chart Widget using Artisan Source: https://filamentphp.com/docs/3.x/panels/getting-started Run this Artisan command to generate a new chart widget. Do not specify a resource, select "admin" for the location, and choose "line chart" as the type when prompted. ```bash php artisan make:filament-widget TreatmentsChart --chart ``` -------------------------------- ### Change modal content alignment Source: https://filamentphp.com/docs/3.x/support/blade-components/modal Use the alignment attribute to set the content alignment to start or center. ```blade {{-- Modal content --}} ``` -------------------------------- ### Add placeholder to value fields Source: https://filamentphp.com/docs/3.x/forms/fields/key-value Set a placeholder text for the value input fields to guide users. ```php use Filament\Forms\Components\KeyValue; KeyValue::make('meta') ->valuePlaceholder('Property value') ``` -------------------------------- ### Create a New Filament Panel using Artisan Source: https://filamentphp.com/docs/3.x/panels/configuration Use this Artisan command to generate a new panel configuration file and register it. The panel will be accessible at '/app' by default. ```bash php artisan make:filament-panel app ``` -------------------------------- ### Add placeholder to key fields Source: https://filamentphp.com/docs/3.x/forms/fields/key-value Set a placeholder text for the key input fields to guide users. ```php use Filament\Forms\Components\KeyValue; KeyValue::make('meta') ->keyPlaceholder('Property name') ``` -------------------------------- ### Install Filament Actions Package with Composer Source: https://filamentphp.com/docs/3.x/actions Use this command to add the Filament Actions package to your Laravel project. ```bash composer require filament/actions:"^3.3" -W ``` -------------------------------- ### Set responsive columns using the columns method Source: https://filamentphp.com/docs/3.x/infolists/layout/grid Pass an integer for a fixed column count on large screens or an array of Tailwind breakpoints for responsive behavior. ```php columns(2) ``` ```php columns(['md' => 2, 'xl' => 4]) ``` -------------------------------- ### Implement Standard Pagination in Livewire and Blade Source: https://filamentphp.com/docs/3.x/support/blade-components/pagination This demonstrates how to prepare paginated data in a Livewire component and then render it using the Filament pagination Blade component. ```php use App\Models\User; use Illuminate\Contracts\View\View; use Livewire\Component; class ListUsers extends Component { // ... public function render(): View { return view('livewire.list-users', [ 'users' => User::query()->paginate(10), ]); } } ``` ```blade ``` -------------------------------- ### Define Action for Programmatic Triggering Source: https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component Define a Filament action that can be triggered programmatically. This example includes confirmation and a debug output. ```php use Filament\Actions\Action; public function testAction(): Action { return Action::make('test') ->requiresConfirmation() ->action(function (array $arguments) { dd('Test action called', $arguments); }); } ``` -------------------------------- ### Scaffold new Laravel project with Filament Widgets Source: https://filamentphp.com/docs/3.x/widgets/installation Install Livewire, Alpine.js, and Tailwind CSS in a new Laravel project with Filament scaffolding. Only run these commands in a fresh Laravel project as they will overwrite existing files. ```bash php artisan filament:install --scaffold --widgets npm install npm run dev ``` -------------------------------- ### Install Filament Table Builder with Composer Source: https://filamentphp.com/docs/3.x/tables Use this command to add the Filament Table Builder package to your Laravel project. ```bash composer require filament/tables:"^3.3" -W ``` -------------------------------- ### Publish new configuration and remove legacy files Source: https://filamentphp.com/docs/3.x/tables/upgrade-guide Consolidates configuration into a single file and removes the deprecated tables configuration file. ```bash php artisan vendor:publish --tag=filament-config --force rm config/tables.php ``` -------------------------------- ### Disable Grammarly checks on textarea Source: https://filamentphp.com/docs/3.x/forms/fields/textarea Use disableGrammarly() to prevent Grammarly from analyzing textarea content when the user has the extension installed. ```php use Filament\Forms\Components\Textarea; Textarea::make('description') ->disableGrammarly() ``` -------------------------------- ### Configure all columns globally using Column::configureUsing() Source: https://filamentphp.com/docs/3.x/tables/columns/getting-started Call `Column::configureUsing()` in a service provider's `boot()` method to set default behavior for all column types. Pass a Closure that modifies the column instance. ```php use Filament\Tables\Columns\Column; Column::configureUsing(function (Column $column): void { $column ->toggleable() ->searchable(); }); ``` -------------------------------- ### Set custom search prompt for Filament Select Source: https://filamentphp.com/docs/3.x/forms/fields/select Provide a custom instruction message to users before they start typing in a searchable select. ```php use Filament\Forms\Components\Select; Select::make('author_id') ->relationship(name: 'author', titleAttribute: 'name') ->searchable(['name', 'email']) ->searchPrompt('Search authors by their name or email address') ``` -------------------------------- ### Create multi-step wizard for Filament CreateAction Source: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create Replace the standard form with a steps() array containing Step objects to create a multi-step creation process. ```php use Filament\Forms\Components\MarkdownEditor; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; use Filament\Forms\Components\Wizard\Step; CreateAction::make() ->steps([ Step::make('Name') ->description('Give the category a unique name') ->schema([ TextInput::make('name') ->required() ->live() ->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state))), TextInput::make('slug') ->disabled() ->required() ->unique(Category::class, 'slug'), ]) ->columns(2), Step::make('Description') ->description('Add some extra details') ->schema([ MarkdownEditor::make('description'), ]), Step::make('Visibility') ->description('Control who can view it') ->schema([ Toggle::make('is_visible') ->label('Visible to customers.') ->default(true), ]), ]) ``` -------------------------------- ### Custom validation rule with injected utilities Source: https://filamentphp.com/docs/3.x/forms/validation Inject utilities like $get into custom rules to reference other field values during validation. ```php use Closure; use Filament\Forms\Get; TextInput::make('slug')->rules([ fn (Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) { if ($get('other_field') === 'foo' && $value !== 'bar') { $fail("The {$attribute} is invalid."); } }, ]) ``` -------------------------------- ### Setting a summarizer label Source: https://filamentphp.com/docs/3.x/tables/summaries Customize the label displayed for a summarizer using the label() method. This example sets a custom label for a Sum summarizer. ```php use Filament\Tables\Columns\Summarizers\Sum; use Filament\Tables\Columns\TextColumn; TextColumn::make('price') ->summarize(Sum::make()->label('Total')) ``` -------------------------------- ### Configure Panel Path to Root Source: https://filamentphp.com/docs/3.x/panels/configuration Set the panel to be accessible at the root URL. Ensure no conflicting routes are defined in 'routes/web.php'. ```php use Filament\Panel; public function panel(Panel $panel): Panel { return $panel // ... ->path(''); } ``` -------------------------------- ### Implement Text Constraints in Filament Query Builder Source: https://filamentphp.com/docs/3.x/tables/filters/query-builder Use these examples to filter text fields directly or through relationships within the Query Builder. ```php use Filament ables iltersuilder extconstraint; textconstraint::make('name') // Filter the `name` column textconstraint::make('creatorname') ->relationship(name: 'creator', titleattribute: 'name') // Filter the `name` column on the `creator` relationship ``` -------------------------------- ### Call an action without data Source: https://filamentphp.com/docs/3.x/actions/testing Use `callAction()` to invoke a Filament action. This example tests if an invoice is marked as sent after the action is called. ```php use function Pest\Livewire\livewire; it('can send invoices', function () { $invoice = Invoice::factory()->create(); livewire(EditInvoice::class, [ 'invoice' => $invoice, ]) ->callAction('send'); expect($invoice->refresh()) ->isSent()->toBeTrue(); }); ``` -------------------------------- ### Generate Livewire component with Artisan Source: https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component Create a new Livewire component using the make:livewire command. ```bash php artisan make:livewire ManageProduct ``` -------------------------------- ### Set sub-navigation position in Filament resource Source: https://filamentphp.com/docs/3.x/panels/resources/getting-started Set the $subNavigationPosition property to control where sub-navigation renders: Start (default), End, or Top (as tabs). ```php use Filament\Pages\SubNavigationPosition; protected static SubNavigationPosition $subNavigationPosition = SubNavigationPosition::End; ``` -------------------------------- ### Customize record creation with using() Source: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create Override the default creation process using using() method. Receives $data array and $model class name; must return the created Model instance. ```php use Illuminate\Database\Eloquent\Model; CreateAction::make() ->using(function (array $data, string $model): Model { return $model::create($data); }) ``` -------------------------------- ### Set Section Collapsed by Default in Filament Source: https://filamentphp.com/docs/3.x/infolists/layout/section Use the `collapsed()` method to make a section start in a collapsed state when the page first loads. ```php use Filament\Infolists\Components\Section; Section::make('Cart') ->description('The items you have selected for purchase') ->schema([ // ... ]) ->collapsed() ``` -------------------------------- ### Configure Filament Panel to Use Local Font Provider Source: https://filamentphp.com/docs/3.x/panels/themes Use `LocalFontProvider::class` and provide a `url` to your local stylesheet to serve fonts from your own assets instead of a CDN. ```php use Filament\FontProviders\LocalFontProvider; $panel->font( 'Inter', url: asset('css/fonts.css'), provider: LocalFontProvider::class, ) ``` -------------------------------- ### Create Resource with View Page Source: https://filamentphp.com/docs/3.x/panels/resources/viewing-records Generate a new Filament resource with a View page using the artisan command with the --view flag. ```bash php artisan make:filament-resource User --view ``` -------------------------------- ### Execute code on modal open with mountUsing() Source: https://filamentphp.com/docs/3.x/actions/modals Runs custom logic when the modal opens. Must call $form->fill() to initialize the form unless using fillForm() on the action. Use fill() with an array to populate form data. ```php use Filament\Forms\Form; Action::make('create') ->mountUsing(function (Form $form) { $form->fill(); // ... }) ``` -------------------------------- ### Basic Custom Blade View for Filament Page Source: https://filamentphp.com/docs/3.x/panels/resources/viewing-records Example of a custom Blade template for a Filament page, rendering the infolist, form, and relation managers. ```blade @if ($this->hasInfolist()) {{ $this->infolist }} @else {{ $this->form }} @endif @if (count($relationManagers = $this->getRelationManagers())) @endif ``` -------------------------------- ### Align Section Footer Actions (PHP) Source: https://filamentphp.com/docs/3.x/forms/layout/section Customize the alignment of footer actions within a section using `footerActionsAlignment()`. This example aligns actions to the end. ```php use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Section; use Filament\Support\Enums\Alignment; Section::make('Rate limiting') ->schema([ // ... ]) ->footerActions([ Action::make('test') ->action(function () { // ... }), ]) ->footerActionsAlignment(Alignment::End) ``` -------------------------------- ### Create custom infolist entry via Artisan Source: https://filamentphp.com/docs/3.x/infolists/entries/custom Generates a new entry class and a corresponding Blade view file in the resources/views directory. ```bash php artisan make:infolist-entry StatusSwitcher ``` -------------------------------- ### Create a basic textarea field Source: https://filamentphp.com/docs/3.x/forms/fields/textarea Initialize a textarea component for multi-line string input. Use the make() method with a field name. ```php use Filament\Forms\Components\Textarea; Textarea::make('description') ``` -------------------------------- ### Assert action halted Source: https://filamentphp.com/docs/3.x/actions/testing Check if an action was halted using `assertActionHalted()`. This example verifies that the 'send' action stops if the invoice lacks an email address. ```php use function Pest\Livewire\livewire; it('stops sending if invoice has no email address', function () { $invoice = Invoice::factory(['email' => null])->create(); livewire(EditInvoice::class, [ 'invoice' => $invoice, ]) ->callAction('send') ->assertActionHalted('send'); }); ``` -------------------------------- ### Register the tenant registration page in the Panel Source: https://filamentphp.com/docs/3.x/panels/tenancy Enable the registration page by adding it to the panel configuration using the tenantRegistration() method. ```php use App\Filament\Pages\Tenancy\RegisterTeam; use Filament\Panel; public function panel(Panel $panel): Panel { return $panel // ... ->tenantRegistration(RegisterTeam::class); } ``` -------------------------------- ### Install Filament Form Builder Package with Composer Source: https://filamentphp.com/docs/3.x/forms Use this command to add the Filament Form Builder package to your Laravel project via Composer. ```bash composer require filament/forms:"^3.3" -W ``` -------------------------------- ### Dynamically Label Builder Items by Content (PHP) Source: https://filamentphp.com/docs/3.x/forms/fields/builder This example demonstrates using a closure with the `label()` method to dynamically set a builder item's label based on its `$state` data. Fields used in the label should be `live()` for real-time updates. ```php use Filament\Forms\Components\Builder; use Filament\Forms\Components\TextInput; Builder\Block::make('heading') ->schema([ TextInput::make('content') ->live(onBlur: true) ->required(), // ... ]) ->label(function (?array $state): string { if ($state === null) { return 'Heading'; } return $state['content'] ?? 'Untitled heading'; }) ``` -------------------------------- ### Dynamic Placeholder content with closures Source: https://filamentphp.com/docs/3.x/forms/layout/placeholder Use closures to calculate or fetch content dynamically based on other form field values using the Get utility. ```php use Filament\Forms\Components\Placeholder; use Filament\Forms\Get; Placeholder::make('total') ->content(function (Get $get): string { return '€' . number_format($get('cost') * $get('quantity'), 2); }) ``` -------------------------------- ### Create a simple delete action with confirmation Source: https://filamentphp.com/docs/3.x/actions/overview Use `requiresConfirmation()` to prompt the user before executing the action callback. The action executes without redirecting the user. ```php Action::make('delete') ->requiresConfirmation() ->action(fn () => $this->client->delete()) ``` -------------------------------- ### Call Infolist Action in Pest Source: https://filamentphp.com/docs/3.x/infolists/testing Use `callInfolistAction()` to invoke an infolist action, specifying the component key and action name. This example tests sending an invoice. ```php use function Pest\Livewire\livewire; it('can send invoices', function () { $invoice = Invoice::factory()->create(); livewire(EditInvoice::class, [ 'invoice' => $invoice, ]) ->callInfolistAction('customer', 'send', infolistName: 'infolist'); expect($invoice->refresh()) ->isSent()->toBeTrue(); }); ```