Filament

repository·4.x·Indexed 12 days ago

https://github.com/filamentphp/filament

A TALL stack (Tailwind, Alpine.js, Laravel, Livewire) framework for rapidly building admin panels and application interfaces. It provides a cohesive set of UI components and supports plugins for Spatie Google Fonts and Spatie Media Library, including specialized form components, table columns, and infolist entries.

Tokens
373.1K
Snippets
1.4K
Records
1.6K
Agent score
97%

What's inside Filament

  1. Overview of Filament Table Columns

    4.x

    Table columns are defined within the $table->columns() method using classes from the Filament\Tables\Columns namespace.

    Built-in Columns:

    • TextColumn
    • IconColumn
    • ImageColumn
    • ColorColumn

    Editable Columns (allow in-table updates):

    • SelectColumn
    • ToggleColumn
    • TextInputColumn
    • CheckboxColumn

    You can also create custom columns by implementing the necessary interfaces.

    Columns are typically created using the static make() method, where the argument is the name of the attribute on the Eloquent model. You can use dot notation to access relationship attributes or JSON keys.

    use Filament\Tables\Columns\TextColumn;
    
    TextColumn::make('title')
    TextColumn::make('author.name')
    TextColumn::make('meta.title')
  2. Introduction to Filament Infolists

    4.x
    Filament's infolist package allows you to display a read-only list of data for a specific entity. Infolists are integrated into various parts of the Filament ecosystem, including Panel Resources, Relation Managers, and Action Modals. They are built using an infolist builder that allows you to define a schema of entries to represent your data visually.
  3. Overview of Filament core features

    4.x

    Filament is a collection of UI components for Laravel that allows you to build admin panels and applications quickly. It is built on top of Laravel, Livewire v3, and PHP 8.2+. Key building blocks include:

    • Tables: For browsing and filtering large datasets using columns, actions, and bulk operations.
    • Forms: For building complex, reactive, and state-aware forms.
    • Infolists: For rendering structured, read-only record views.
    • Notifications: For triggering in-app feedback for system events or user actions.
    • Dashboard widgets: For displaying live, data-driven metrics and trends.
    • Action modals: For handling data entry and confirmations via focused modal workflows.
  4. What is Filament?

    4.x

    Filament is a Server-Driven UI (SDUI) framework for Laravel. It allows you to define user interfaces entirely in PHP using structured configuration objects rather than traditional templating. It is built on top of Livewire, Alpine.js, and Tailwind CSS.

    Unlike traditional Server-Rendered UI which relies on static Blade templates, Filament's SDUI approach allows the server to dynamically generate the UI based on real-time configurations and business logic, providing greater flexibility and reactivity.

  5. Built-in layout components in Filament

    4.x

    Filament provides several built-in components to structure your UI. Most of these support the columns() method for grid-based layouts:

    • Grid: A standard multi-column grid.
    • Flex: A flexbox-based container.
    • Fieldset: A container with a legend/border.
    • Section: A container for grouping related content.
    • Tabs: A tabbed interface.
    • Wizard: A multi-step workflow component.
    • Callout: For highlighting information.
    • Empty state: For displaying content when no data is present.
  6. Understand the core building blocks of Filament

    4.x

    A Filament application is primarily composed of three types of components:

    1. Resources: CRUD (Create, Read, Update, Delete) interfaces for managing Eloquent models. They automatically generate List, Create, and Edit pages, and can optionally include a View page.
    2. Widgets: Interactive components used to display data (like charts, numbers, or tables), typically found on dashboards. They are built as Livewire components.
    3. Custom pages: Blank canvases for building specialized interfaces like settings pages or documentation. Like widgets, these are full-page Livewire components.
  7. Core Filament package components

    4.x

    Filament is built upon several core packages that provide the primary building blocks for interfaces. While these are used internally by Filament panels, they can also be used independently in your own applications or within custom Filament plugins:

    • Action: For handling user interactions and operations.
    • Form: For building complex input forms.
    • Infolist: For displaying read-only data in a structured layout.
    • Notifications: For displaying transient messages to users.
    • Schema: For defining the structural layout of components.
    • Table: For displaying and managing data in tabular formats.
    • Widget: For displaying dashboard-style content or specialized UI blocks.
  8. Filament Blade components

    4.x

    Filament provides a comprehensive suite of Blade components that are used internally across the ecosystem. These components can be consumed directly in your own Blade templates to ensure a consistent UI design that matches the Filament aesthetic.

    Available Blade components include:
    - Avatar
    - Badge
    - Button
    - Breadcrumbs
    - Callout
    - Checkbox
    - Dropdown
    - Empty state
    - Fieldset
    - Icon button
    - Input
    - Input wrapper
    - Link
    - Loading indicator
    - Modal
    - Pagination
    - Section
    - Select
    - Tabs
  9. What is the Builder component?

    4.x

    The Builder component allows you to output a JSON array of repeated form components. Unlike a repeater, which uses a single schema for all items, a Builder allows you to define multiple different schema "blocks" that can be repeated in any order. This is ideal for building complex structures like web page content (e.g., a mix of headings, paragraphs, and images).

    Important Implementation Note: It is recommended to store Builder data in a JSON database column. If using Eloquent, ensure the column has an array cast.

    use Filament\Forms\Components\Builder;
    use Filament\Forms\Components\Builder\Block;
    use Filament\Forms\Components\TextInput;
    
    Builder::make('content')
        ->blocks([
            Block::make('heading')
                ->schema([
                    TextInput::make('content')->required(),
                ]),
            // Add more blocks here
        ])
    use Filament\Forms\Components\Builder;
    use Filament\Forms\Components\Builder\Block;
    use Filament\Forms\Components\FileUpload;
    use Filament\Forms\Components\Select;
    use Filament\Forms\Components\Textarea;
    use Filament\Forms\Components\TextInput;
    
    Builder::make('content')
        ->blocks([
            Block::make('heading')
                ->schema([
                    TextInput::make('content')
                        ->label('Heading')
                        ->required(),
                    Select::make('level')
                        ->options([
                            'h1' => 'Heading 1',
                            'h2' => 'Heading 2',
                            'h3' => 'Heading 3',
                            'h4' => 'Heading 4',
                            'h5' => 'Heading 5',
                            'h6' => 'Heading 6',
                        ])
                        ->required(),
                ])
                ->columns(2),
            Block::make('paragraph')
                ->schema([
                    Textarea::make('content')
                        ->label('Paragraph')
                        ->required(),
                ]),
            Block::make('image')
                ->schema([
                    FileUpload::make('url')
                        ->label('Image')
                        ->image()
                        ->required(),
                    TextInput::make('alt')
                        ->label('Alt text')
                        ->required(),
                ]),
        ])
  10. Configure email change verification behavior

    4.x

    When using profile() alongside emailChangeVerification(), Filament implements a secure email update flow:

    1. The user submits a new email address via the profile form.
    2. A verification link is sent to the new address (valid for 60 minutes).
    3. A security link is simultaneously sent to the old address, allowing the user to block the change if it was unauthorized.
    4. The database is only updated once the user clicks the link in the new email.
  11. Use the Split layout to allow columns to stack on mobile

    4.x

    The Split component wraps around columns to create a responsive layout. By default, columns within a Split appear side-by-side. You can use the from() method to specify a responsive breakpoint (e.g., md) where the columns should start appearing horizontally. Before this breakpoint, the columns will stack vertically on top of each other.

    use Filament\Tables\Columns\Layout\Split;
    use Filament\Tables\Columns\ImageColumn;
    use Filament\Tables\Columns\TextColumn;
    
    Split::make([
        ImageColumn::make('avatar')->circular(),
        TextColumn::make('name')->weight(FontWeight::Bold),
        TextColumn::make('email'),
    ])->from('md')
  12. Fuse multiple fields together using FusedGroup

    4.x

    The FusedGroup component allows you to visually "fuse" multiple input fields into a single cohesive UI element. This is best used with TextInput, Select, DateTimePicker, and ColorPicker components.

    To use it, pass an array of field components to the make() method of FusedGroup. You can also add a group-level label using label() and control the layout using columns() to display fields horizontally on desktop.

    use Filament\Forms\Components\Select;
    use Filament\Forms\Components\TextInput;
    use Filament\Schemas\Components\FusedGroup;
    
    FusedGroup::make([
        TextInput::make('city')
            ->placeholder('City'),
        Select::make('country')
            ->placeholder('Country')
            ->options([
                // ...
            ]),
    ])
        ->label('Location')
        ->columns(2)