### Composer Authentication Prompt Example for Plugin Installation Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Example showing the expected authentication prompt when installing the plugin via Composer, requiring your email and license key. ```Text Loading composer repositories with package information Authentication required (filament-cms-website-plugin.composer.sh): Username: philo@anystack.sh Password: 8c21df8f-6273-4932-b4ba-8bcc723ef500:anystack.sh ``` -------------------------------- ### Installing Filament and frontend dependencies Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/mohamedsabil83-customizing-colors-per-user-outside-of-a-panel.md Installs Filament using Composer, runs the Filament installation command with scaffolding and panel options, and then installs and compiles frontend assets using npm. ```bash composer require filament/filament:"^3.0-stable" -W php artisan filament:install --scaffold --panels npm install npm run dev ``` -------------------------------- ### Installing Filament via Composer Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Navigate into the newly created project directory and use Composer to require the Filament package version 2.x. This downloads and installs Filament and its dependencies. ```bash cd filament-custom-theme composer require filament/filament:"^2.0" ``` -------------------------------- ### Installing Pest (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Installs the Pest testing framework and its Laravel plugin as development dependencies using Composer, then runs the Pest installation command. This sets up the testing environment. ```bash composer require pestphp/pest-plugin-laravel --dev php artisan pest:install ``` -------------------------------- ### Installing Filament CMS Website Plugin via Composer Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Use the composer require command to download and install the Filament CMS Website Plugin into your project. ```Bash composer require solution-forest/filament-cms-website-plugin ``` -------------------------------- ### Install Tailwind CSS and Dependencies (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Installs necessary development dependencies for Tailwind CSS theming, including Tailwind itself, forms and typography plugins, autoprefixer, and tippy.js. Initializes a Tailwind configuration file. ```bash npm install tailwindcss @tailwindcss/forms @tailwindcss/typography autoprefixer tippy.js --save-dev npx tailwindcss init ``` -------------------------------- ### Creating New Laravel Project (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Initializes a new Laravel project named `filament-tdd-example` using the Laravel installer command. This is the first step in setting up the development environment. ```bash laravel new filament-tdd-example ``` -------------------------------- ### Installing Filament (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Changes the directory to the new project and installs the Filament package version 2.x using Composer. This adds Filament as a dependency to the project. ```bash cd filament-tdd-example composer require filament/filament:"^2.0" ``` -------------------------------- ### Running Filament CMS Plugin Installation Command Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Execute the artisan command to publish configuration, migrations, layout files, and create initial page data for the Filament CMS plugin. ```Bash php artisan filament-cms:install ``` -------------------------------- ### Creating a new Laravel project Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Use the Laravel installer to create a new project directory named 'filament-custom-theme'. This command initializes the basic Laravel application structure. ```bash laravel new filament-custom-theme ``` -------------------------------- ### Building and Serving the Project (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md This command sequence first builds the project's front-end assets using npm, and then starts the PHP Artisan development server to make the application accessible locally. ```bash npm run build && php artisan serve ``` -------------------------------- ### Install Sushi Package (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-consume-an-external-api-with-filament-tables.md Installs the `calebporzio/sushi` package using Composer, which is required for using models backed by arrays or external data sources like APIs. ```bash composer require calebporzio/sushi ``` -------------------------------- ### Example Filament Resource for Data-type Page Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Provides an example PHP class defining a Filament Resource for a 'Link' data-type page, extending the base resource and configuring pages and templates. ```php Pages\ListLinks::route('/'), 'edit' => Pages\EditLink::route('/{record:id}/edit'), 'create' => Pages\CreateLink::route('/create'), ]; } public static function getTemplate(): string { return Template::class; } } ``` -------------------------------- ### Installing Filament via Composer Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-refresh-widgets-when-table-actions-are-fired.md Changes the directory to the project root and installs the Filament package using Composer. ```bash cd filament-widget-examples composer require filament/filament ``` -------------------------------- ### Example Template for Data-type Page Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Provides an example PHP class defining a template for a 'Link' data-type page, extending the base template and implementing the CmsPageTemplate contract. ```php [ 'resources' => [ 'cms_page' => \App\Filament\Resources\CmsPageResource::class, 'cms_page_navigation_category' => \App\Filament\Resources\CmsPageNavigationCategoryResource::class, 'cms_tag' => \App\Filament\Resources\CmsTagResource::class, ], 'navigation' => [ 'icon' => [ \App\Filament\Resources\CmsPageResource::class => 'heroicon-o-document', \App\Filament\Resources\CmsPageNavigationCategoryResource::class => 'heroicon-o-bars-3-center-left', CmsTagResource::class => 'heroicon-o-tag', ], 'sort' => [ \App\Filament\Resources\CmsPageResource::class => -10, \App\Filament\Resources\CmsTagResource::class => -9, \App\Filament\Resources\CmsPageNavigationCategoryResource::class => -8, ], ], ... 'models' => [ 'cms_page' => \App\Models\CmsPage::class, 'cms_published_page' => \App\Models\CmsPublishedPage::class, 'cms_page_navigation' => \App\Models\CmsPageNavigation::class, 'cms_page_navigation_category' => \App\Models\CmsPageNavigationCategory::class, 'cms_tag' => \App\Models\CmsTag::class, 'cms_taggable' => \App\Models\CmsTaggable::class, 'cms_tag_category' => \App\Models\CmsTagCategory::class, ] ... ]; ``` -------------------------------- ### Install league/iso3166 package Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/josefbehr-how-to-implement-a-localized-country-select-field.md Use Composer to install the league/iso3166 package, which provides comprehensive ISO 3166 country data necessary for populating the select field options. ```bash $ composer require league/iso3166 ``` -------------------------------- ### Setting minimum-stability in composer.json Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/mohamedsabil83-customizing-colors-per-user-outside-of-a-panel.md Modifies the `composer.json` file to set the `minimum-stability` property to 'dev', which is required for installing beta dependencies like Livewire 3. ```json "minimum-stability": "dev", ``` -------------------------------- ### Get All Navigations (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Retrieve all registered navigation menus using the Filament CMS Facade. ```php \SolutionForest\FilamentCms\Facades\FilamentCms::getNavigations() ``` -------------------------------- ### Filament Infolists: Displaying Code Snippets Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-filament-v4-beta-feature-overview.md The 'Code entry' feature allows presenting highlighted code snippets within Filament infolists. It leverages Phiki for server-side code highlighting, providing a clean way to display code examples or configurations. ```APIDOC Infolist Component: Code Entry Purpose: Allows presenting highlighted code snippets within an infolist. Highlighting Engine: Uses Phiki for server-side code highlighting. Usage: Integrate a code entry component into your infolist schema. ``` -------------------------------- ### Configuring Composer Repository for Filament CMS Plugin Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Add the custom composer repository URL to your project's composer.json file to allow installation of the Filament CMS Website Plugin. ```JSON { "repositories": [ { "type": "composer", "url": "https://filament-cms-website-plugin.composer.sh" } ] } ``` -------------------------------- ### Update Filament CMS Plugin (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Use this Artisan command to check for and install updates for the Filament CMS website plugin. It handles migration publishing and prompting for execution. ```bash php artisan filament-cms:update ``` -------------------------------- ### Example CMS Page Template Class (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Defines a basic Filament CMS page template with a title, schema for form fields (a text input), and a renderer. Implements the CmsPageTemplate contract. ```php schema([ Forms\Components\TextInput::make('content') ->label(__('filament-cms::filament-cms.fields.cms_page.block-template.content')) ]), ]; } public static function getRenderer(): ?string { return static::$view ?? AtomicDesignPageRenderer::class; } public static function hiddenOnTemplateOptions(): bool { return false; } } ``` -------------------------------- ### Response for Missing Plugin Image - Markdown Source: https://github.com/filamentphp/filamentphp.com/blob/main/PLUGIN_REVIEW_GUIDELINES.md Provides a standard response when a submitted plugin is missing an image, directing the contributor to the contributing guide for requirements and suggesting a banner generator tool. ```markdown Hey! Your plugin does not currently have an image. Please add one as outlined in our [Contributing Guide](https://github.com/filamentphp/filamentphp.com#submitting-a-plugin). The image must follow the 16:9 aspect ratio, be at least 2560x1440 pixels, and preferably be a JPEG. You can use [Beyond Code's banner generator](https://banners.beyondco.de) to create a banner for your plugin. Let us know once this is added! ``` -------------------------------- ### Generating a Filament Panel Provider Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/shaung-bhone-overriding-the-filament-panel-provider.md This command is used to generate a new Filament panel provider class via the Artisan command-line tool. It creates a starting point for configuring a specific panel. ```bash php artisan make:filament-panel client ``` -------------------------------- ### Using Filament Standalone Form with statePath (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Example of using Filament's Standalone Mode in a Livewire component, demonstrating the use of the `HasForms` and `InteractsWithForms` traits, the `mount` method for initialization, the `form` method to define the schema, and the crucial `statePath` method to bind form data to a public array property. ```PHP class CreateCategory extends Component implements HasForms { use InteractsWithForms; public ?array $data = []; public function mount(): void { $this->form->fill(); // Important for initializing the form } public function form(Form $form): Form { return $form ->schema([ TextInput::make('name'), TextInput::make('slug'), ... ]) ->statePath('data'); // Important for storing form data } ... } ``` -------------------------------- ### Using Filament Standalone Form with Public Properties (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Alternative example of using Filament's Standalone Mode in a Livewire component without `statePath`, showing how to bind form fields directly to public properties defined on the Livewire component. ```PHP class CreateCategory extends Component implements HasForms { use InteractsWithForms; // Add public properties for each field in the form schema public ?string $name = null; public ?string $slug = null; ... public function mount(): void { $this->form->fill(); } public function form(Form $form): Form { return $form ->schema([ TextInput::make('name'), TextInput::make('slug'), ... ]); } ... } ``` -------------------------------- ### Using a Custom Importer with FilamentPHP ImportAction (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/alexandersix-handling-bulk-imports-in-filament.md This snippet shows how to modify the `getActions` method in a FilamentPHP `ListRecords` page (`ListBooks`) to use the custom `BookImporter` class with the `ImportAction`. It demonstrates replacing the default importer setup with the specific `BookImporter::class`. ```php importer(), // [tl! remove ~~:1] ->importer(BookImporter::class), // [tl! add ~~:1] Actions\CreateAction::make(), ]; } } ``` -------------------------------- ### Specifying Multiple Documentation URLs in YAML Source: https://github.com/filamentphp/filamentphp.com/blob/main/README.md This YAML snippet demonstrates how to provide version-specific documentation URLs for a plugin. Instead of a single `docs_url`, an array of key-value pairs (`docs_urls`) is used, where keys represent versions and values are the raw Markdown URLs. The first entry is the default. ```yaml docs_urls: v3: https://raw.githubusercontent.com/author/plugin/3.x/README.md v2: https://raw.githubusercontent.com/author/plugin/2.x/README.md ``` -------------------------------- ### Defining Plugin Metadata in Markdown Frontmatter Source: https://github.com/filamentphp/filamentphp.com/blob/main/README.md This snippet shows the required YAML frontmatter structure for a plugin submission Markdown file. It includes essential fields like name, slug, author, categories, description, URLs for documentation and Discord, GitHub repository, theme and translation support flags, supported versions, and publication date. ```md --- name: Spatie Media Library slug: filament-spatie-media-library author_slug: filament categories: [form-builder, form-field, spatie, table-builder, table-column] description: Filament support for `spatie/laravel-medialibrary`. discord_url: https://discord.com/channels/883083792112300104/1080807837833384017 docs_url: https://raw.githubusercontent.com/filamentphp/spatie-laravel-media-library-plugin/3.x/README.md github_repository: filamentphp/spatie-laravel-media-library-plugin has_dark_theme: true has_translations: true versions: [2, 3] publish_date: 2023-08-01 --- ``` -------------------------------- ### Running Database Migrations and Seeding Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Execute the Artisan migrate command with the --seed flag. This runs all pending database migrations to create the tables and then runs the database seeders to populate them with data. ```bash php artisan migrate --seed ``` -------------------------------- ### Publishing Filament Configuration Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Run the Artisan command to publish Filament's configuration file. This makes the configuration file available in your application's config directory for customization. ```bash php artisan vendor:publish --tag=filament-config ``` -------------------------------- ### Get Vite Asset URL in PHP Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/modrictin-include-vite-built-js-and-css-files-in-your-project.md Demonstrates how to get the URL for a Vite-built asset using the Vite facade, specifying a hot file and the build directory as the second parameter to the `asset()` function. ```php Vite::useHotFile('admin.hot') ->asset('resources/sass/admin/app.scss','admin') ``` -------------------------------- ### Running Migrations and Seeding (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Executes the database migrations to create the tables and then runs the seeders to populate the tables with the fake data defined in the factories and seeder file. ```bash php artisan migrate --seed ``` -------------------------------- ### Install Brazilian Validator Package (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-brazilian-cpfcnpj-field.md Installs the `laravellegends/pt-br-validator` package using Composer. This package provides validation rules specifically for Brazilian CPF and CNPJ numbers, which are required for the validation rules used in the Filament fields. ```bash composer require laravellegends/pt-br-validator ``` -------------------------------- ### Create Product Model and Resource (Artisan) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-consume-an-external-api-with-filament-tables.md Generates the `Product` Eloquent model and a basic FilamentPHP resource for the `Product` model using Artisan commands. The `--simple` and `--view` flags configure the resource. ```bash php artisan make:model Product php artisan make:filament-resource Product --simple --view ``` -------------------------------- ### Creating Filament Resources with Artisan - Bash Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md These commands use the Artisan CLI to generate basic Filament resources for the User and Post models. The --simple flag creates resources with minimal default configurations. ```bash php artisan make:filament-resource User --simple php artisan make:filament-resource Post --simple ``` -------------------------------- ### Using RichEditor with Custom Tailwind Classes in Helper Text (Error Example) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Demonstrates adding a RichEditor component with helper text containing HTML that uses custom Tailwind classes. This example shows the code that will fail to apply the custom CSS unless Tailwind is configured correctly. ```php RichEditor::make('content') ->columnSpanFull() ->helperText(new HtmlString(<<<'HTML'
You can use Markdown to format your content.
HTML) ), ``` -------------------------------- ### Creating Post Model, Migration, and Factory (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Generates the `Post` Eloquent model, its corresponding database migration file, and a model factory using the Artisan command. This sets up the necessary files for the Post resource. ```bash php artisan make:model Post -m -f ``` -------------------------------- ### Creating Filament User Resource and Widget Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Use Artisan commands to generate a Filament resource for the User model and a Filament widget associated with the User resource. The --simple flag creates a basic resource structure. ```bash php artisan make:filament-resource User --simple php artisan make:filament-widget UserOverview --resource=UserResource ``` -------------------------------- ### Get Specific Navigation (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Retrieve a specific navigation menu by its key (e.g., 'main-menu') using the Filament CMS Facade. ```php \SolutionForest\FilamentCms\Facades\FilamentCms::getNavigations('main-menu') ``` -------------------------------- ### Updating Database Seeder Run Method Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Modify the DatabaseSeeder (database/seeders/DatabaseSeeder.php) to use the updated User factory to create 50 fake user records. This populates the database with test data. ```php //database\seeders\DatabaseSeeder.php public function run() { \App\Models\User::factory(50)->create(); } ``` -------------------------------- ### Setting up Filament Import Prerequisites Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/alexandersix-handling-bulk-imports-in-filament.md Runs necessary Laravel Artisan commands to create database tables for job batches, notifications, and Filament's import action, followed by running the migrations. ```bash php artisan queue:batches-table php artisan notifications:table php artisan vendor:publish --tag=filament-actions-migrations php artisan migrate ``` -------------------------------- ### Mounting QR Connect Livewire Component (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/andreaskviby-qr-code-onboarding.md Implements the `mount` method for the Livewire component handling QR code scans. It retrieves the code from the URL, finds the corresponding QR connection record, loads associated customer and place data, increments the view count, and throws a validation error if the code is invalid. ```PHP public function mount($code) { $this->code = $code; $app_code = QRConnection::where('code', $this->code)->first(); if ($app_code) { $this->customer = $app_code->customer; $this->company = $this->customer->name; if ($app_code->place_id !== null) { $this->place = $app_code->place; $this->place_name = $this->place->name; } $app_code->views = $app_code->views + 1; $app_code->save(); } else { throw ValidationException::withMessages(['company' => 'There is no valid code, contact your administrator']); } } ``` -------------------------------- ### Create CMS Page Template Command (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Run this Artisan command to generate a new CMS page template class and its corresponding view file. ```bash php artisan filament-cms:page-template MyTemplate ``` -------------------------------- ### Creating Customers Table (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/andreaskviby-qr-code-onboarding.md Defines the database schema for the 'customers' table, including fields for name, approval status, domain, and timestamps. It sets up a standard customer record structure. ```PHP Schema::create('customers', function (Blueprint $table) { $table->id(); $table->string('name'); $table->boolean('approved')->default(false); $table->string('domain'); $table->timestamps(); }); ``` -------------------------------- ### Response for Invalid Author Avatar Dimensions - Markdown Source: https://github.com/filamentphp/filamentphp.com/blob/main/PLUGIN_REVIEW_GUIDELINES.md Provides a standard response when an author's avatar does not meet the required 1:1 aspect ratio or minimum dimensions, referencing the contributing guide. ```markdown Hey! Your author avatar must follow a 1:1 aspect ratio, be at least 1000x1000 pixels in size, and preferably be a JPEG file, as outlined in our [Contributing Guide](https://github.com/filamentphp/filamentphp.com#setting-up-an-author-profile). Please make the necessary adjustments and let us know once this is resolved. ``` -------------------------------- ### Disabling Default Filament CMS Authentication (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Shows how to disable the default authentication setup provided by the Filament CMS plugin by returning `false` from the closure passed to the `registerCmsAuthenticationUsing` method. ```php FilamentCmsPanel::make() ->registerCmsAuthenticationUsing(fn () => false) ``` -------------------------------- ### Response for Paid Plugin Review - Markdown Source: https://github.com/filamentphp/filamentphp.com/blob/main/PLUGIN_REVIEW_GUIDELINES.md Informs the contributor that their paid plugin submission has passed the initial guideline review and requires a secondary review of the private repository by another team member. ```markdown Hey! Thank you for your contribution. This is an initial review to ensure your submission complies with our guidelines. Since your plugin is paid, your private repository will need to be reviewed by another team member before it can be fully approved and published. ``` -------------------------------- ### Implementing Wizard in Filament Create Page (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Shows how to integrate a Filament Wizard component into a Resource Create Page by using the `HasWizard` trait and defining the steps in the `getSteps` method. This is the correct way to use Wizards in Resource pages. ```PHP use App\Filament\Resources\CategoryResource; use Filament\Resources\Pages\CreateRecord; class CreateCategory extends CreateRecord { use CreateRecord\Concerns\HasWizard; protected static string $resource = CategoryResource::class; protected function getSteps(): array { return [ // ... ]; } } ``` -------------------------------- ### Require PHP intl extension in composer.json Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/josefbehr-how-to-implement-a-localized-country-select-field.md Add the 'ext-intl' requirement to your project's composer.json file. The PHP intl extension is crucial for locale-aware functions like getting localized country names. ```json "require": { ... "ext-intl": "*" }, ``` -------------------------------- ### Creating a new Laravel project Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/mohamedsabil83-customizing-colors-per-user-outside-of-a-panel.md Initializes a new Laravel project named `custom-frontend-color` and navigates into the project directory. ```bash laravel new custom-frontend-color cd ./custom-frontend-color ``` -------------------------------- ### Configuring Database Seeder (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Modifies the `DatabaseSeeder`'s `run` method to create 10 fake users and 10 fake posts using their respective factories. This populates the database with test data. ```php //database\seeders\DatabaseSeeder.php public function run() { \App\Models\User::factory(10)->create(); \App\Models\Post::factory(10)->create(); } ``` -------------------------------- ### Configuring Sub-Navigation Position in Filament Panels Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-filament-v4-beta-feature-overview.md The default position of sub-navigation in Filament panels can now be globally overridden. Options include `Start` (default), `End` (bottom), and `Top` (tabs) using the `subNavigationPosition()` method. ```APIDOC Method: subNavigationPosition(string $position): static Description: Sets the default position for sub-navigation within the panel. Parameters: $position: The desired position. - 'Start': Default position, at the start of each page. - 'End': Renders at the bottom of the page. - 'Top': Displays as tabs at the top of the page. ``` -------------------------------- ### Retrieving Content-type Records (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Use the `getContentType` utility method from `SolutionForest\FilamentCms\Support\Utils` to retrieve all records associated with a specific content-type page, identified by its slug (e.g., 'products'). The `get()` method fetches the collection of records. ```php \SolutionForest\FilamentCms\Support\Utils::getContentType('products')->get(); ``` -------------------------------- ### Creating QR Connections Table (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/andreaskviby-qr-code-onboarding.md Defines the database schema for the 'qr_connections' table used to link QR codes to customers and optional places. Includes a unique code, foreign keys to customers and places, and a view counter. ```PHP Schema::create('qr_connections', function (Blueprint $table) { $table->id(); $table->string('code')->unique(); $table->foreignIdFor(\App\Models\Customer::class, 'customer_id'); $table->foreignIdFor(\App\Models\Place::class, 'place_id')->nullable(); $table->bigInteger('views')->default(0); $table->timestamps(); }); ``` -------------------------------- ### Defining a User Route in Laravel web.php Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/mohamedsabil83-customizing-colors-per-user-outside-of-a-panel.md Configures a GET route in `web.php` that captures a `user` parameter and directs the request to the `UserController`'s `__invoke` method. This sets up the URL structure for accessing user pages. ```php // routes/web.php Route::get('/{user}', UserController::class); ``` -------------------------------- ### Register Custom Theme in Service Provider (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Registers the custom CSS theme file (resources/css/app.css) with Filament using the Filament::registerTheme method within the boot method of a service provider, ensuring the theme is applied when Filament is served. It uses Vite for asset compilation. ```php //app\Providers\AppServiceProvider.php use Filament\Facades\Filament; use Illuminate\Foundation\Vite; public function boot() { Filament::serving(function () { // Using Vite Filament::registerTheme( app(Vite::class)('resources/css/app.css'), ); }); } ``` -------------------------------- ### Creating Filament CMS Content-type Page (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Use this Artisan command to generate the necessary files (page data, template, views, and Filament resource) for a new content-type page. Replace 'Product' with the desired model name and 'products' with the desired slug. ```bash php artisan filament-cms:content-type-page Product products ``` -------------------------------- ### Add CNPJ Field (Filament 3.x PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-brazilian-cpfcnpj-field.md Creates a Filament TextInput field named 'cnpj' with a fixed mask for CNPJ numbers ('99.999.999/9999-99'). This field is specifically for CNPJ input and applies the 'cnpj' validation rule provided by the installed package. ```php TextInput::make('cnpj') ->mask('99.999.999/9999-99') ->rule('cnpj') ``` -------------------------------- ### Add CPF Field (Filament 3.x PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-brazilian-cpfcnpj-field.md Creates a Filament TextInput field named 'cpf' with a fixed mask for CPF numbers ('999.999.999-99'). This field is specifically for CPF input and applies the 'cpf' validation rule provided by the installed package. ```php TextInput::make('cpf') ->mask('999.999.999-99') ->rule('cpf') ``` -------------------------------- ### Implementing Wizard Steps in Filament Action (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Illustrates how to define steps for a Filament Wizard component when used within a Filament Action, such as a CreateAction, by using the `steps()` method. ```PHP CreateAction::make() ->steps([ // ... ]), ``` -------------------------------- ### Defining QR Connect Route (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/andreaskviby-qr-code-onboarding.md Registers a new web route `/connect/{code}` that maps to the `\App\Http\Livewire\Connect\Register` Livewire component. This route is intended to be the target URL for the generated QR codes. ```PHP Route::get('connect/{code}', \App\Http\Livewire\Connect\Register::class) ->name('connect'); ``` -------------------------------- ### Creating Places Table (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/andreaskviby-qr-code-onboarding.md Defines the database schema for the 'places' table, representing locations within a customer. Includes address details, GPS coordinates, and a foreign key relationship to the 'customers' table. ```PHP Schema::create('places', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('street_address')->nullable(); $table->string('zipcode')->nullable(); $table->string('city')->nullable(); $table->string('extra_address')->nullable(); $table->text('description')->nullable(); $table->string('gps_lat',18)->nullable(); $table->string('gps_lon',18)->nullable(); $table ->foreignId('customer_id') ->index() ->constrained() ->cascadeOnDelete(); $table->timestamps(); }); ``` -------------------------------- ### Configuring Forge NGINX for Docs Routing Source: https://github.com/filamentphp/filamentphp.com/blob/main/README.md Modifies the default Forge NGINX configuration to route 403 errors to index.php, ensuring Laravel handles requests for directories like 'docs' instead of NGINX returning a 403 Forbidden error. ```Nginx error_page 403 /index.php; error_page 404 /index.php; ``` -------------------------------- ### Configure PostCSS (JavaScript) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Configures the PostCSS file (postcss.config.js) to use Tailwind CSS and Autoprefixer plugins for processing CSS files. ```javascript //postcss.config.js module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, }, } ``` -------------------------------- ### Running Pest Tests - Bash Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md This command executes the Pest test runner for the project. It runs all tests defined in the project's test suite, including the Livewire tests for the Filament resources. ```bash ./vendor/bin/pest ``` -------------------------------- ### Filament Forms: Automatic Type Casting for Field State Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-filament-v4-beta-feature-overview.md Form field state is now automatically cast to the correct data type, improving type consistency. For example, a Select field bound to an enum will return an instance of the enum, reducing the need for manual casting. ```APIDOC Form Field State Type Casting: Behavior: Automatically casts field state to the correct data type (e.g., enum instances for Select fields). Benefit: Reduces manual casting and improves type consistency when accessing state via $state or $get(). ``` -------------------------------- ### Debugging Local Website Content Issues Source: https://github.com/filamentphp/filamentphp.com/blob/main/README.md Provides Artisan commands to clear various caches (Orbit cache, general cache) and optimize images, commonly used when debugging missing content or image display problems in a local Filament website development environment. ```Bash php artisan clear-orbit-cache ``` ```Bash php artisan cache:clear ``` ```Bash php artisan optimize-images ``` -------------------------------- ### Implementing Wizard in Filament Edit Page (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Shows how to integrate a Filament Wizard component into a Resource Edit Page by using the `HasWizard` trait and defining the steps in the `getSteps` method. This is the correct way to use Wizards in Resource pages. ```PHP use App\Filament\Resources\CategoryResource; use Filament\Resources\Pages\EditRecord; class EditCategory extends EditRecord { use EditRecord\Concerns\HasWizard; protected static string $resource = CategoryResource::class; protected function getSteps(): array { return [ // ... ]; } } ``` -------------------------------- ### Response for Article/Trick Review Process - Markdown Source: https://github.com/filamentphp/filamentphp.com/blob/main/PLUGIN_REVIEW_GUIDELINES.md Informs the contributor that their article or trick submission has passed the initial guideline review and will undergo a secondary review for content accuracy and grammar. ```markdown Hey! Thank you for your contribution. This is an initial review to ensure everything complies with our guidelines. The content of your article or trick will be reviewed by another team member before it can be fully approved and published on the website. ``` -------------------------------- ### Author Profile Markdown File Structure Source: https://github.com/filamentphp/filamentphp.com/blob/main/README.md This snippet shows the required structure for creating an author profile file in the `content/authors` directory. It uses YAML frontmatter for metadata like name, slug, and social URLs, followed by a Markdown section for the author's bio. ```Markdown --- name: Dan Harrin slug: dan-harrin github_url: https://github.com/danharrin twitter_url: https://twitter.com/danjharrin mastodon_url: https://phpc.social/@danharrin sponsor_url: https://github.com/sponsors/danharrin --- Your bio should be written in Markdown here. In the future, we may introduce an Author page where people can see your contributions, so feel free to write a little about yourself. Please check the grammar and spelling of this description, preferably using [Grammarly](https://www.grammarly.com). It should be in full sentences. ``` -------------------------------- ### Adding Widget to ManageUsers Page Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Modify the ManageUsers page class (app/Filament/Resources/UserResource/Pages/ManageUsers.php) to include the UserOverview widget in the `getHeaderWidgets` method. This displays the widget on the user management page. ```php //app\Filament\Resources\UserResource\Pages\ManageUsers.php use App\Filament\Resources\UserResource\Widgets\UserOverview; protected function getHeaderWidgets(): array { return [ UserOverview::class, ]; } ``` -------------------------------- ### Using TagsInput with default() Method (Error on Edit Page Example) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Illustrates the use of the `default()` method on a `TagsInput` component. While this works on Create pages, it will not apply the default value on Edit pages if the model's attribute is null, as `default()` is only used when no existing data is present. ```php TagsInput::make('tags') ->default([ 'Laravel', 'Livewire', 'Filament', ]), ``` -------------------------------- ### Running Pest Tests (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Executes the Pest test suite for the project using the Pest executable located in the vendor bin directory. This runs all defined tests and reports the results. ```bash ./vendor/bin/pest ``` -------------------------------- ### Check Other Table Events in Updated Hook (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-refresh-widgets-when-table-actions-are-fired.md Provides examples of how to check for other specific table-related events within the `updated` Livewire lifecycle hook in a FilamentPHP page class. It shows how to check if the updated property name (`$name`) contains `tableSearchQuery` (for the search input) or `tableFilters` (for the filter form). ```PHP //text input in the top right of the table if (Str::of($name)->contains('tableSearchQuery')) { ... } //the table filter form if (Str::of($name)->contains('tableFilters')) { ... } ``` -------------------------------- ### Combining relationship() and options() in Select Component (Error Example) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-form-builder-common-errors-to-avoid.md Shows an incorrect usage where both `relationship()` and `options()` methods are called on a `Select` component. Using `relationship()` is sufficient as it automatically fetches options based on the defined Eloquent relationship, making the `options()` call redundant and potentially problematic. ```php Select::make('categories') ->multiple() ->preload() ->relationship( name: 'categories', titleAttribute: 'name' ) ->options(Category::wherePublished(true)->pluck('name', 'id')), // Don't use this ``` -------------------------------- ### Running Tests using Pest (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md This command executes the test suite using Pest, a testing framework for PHP. Running this command verifies that the implemented policy logic correctly restricts access as intended by the tests. ```Bash ./vendor/bin/pest ``` -------------------------------- ### Create LocalizedCountrySelect Filament component Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/josefbehr-how-to-implement-a-localized-country-select-field.md Define a custom PHP class that extends Filament's base Select component. The setUp method is overridden to fetch country data from ISO3166 and populate the options array with localized country names using Locale::getDisplayRegion based on the current application locale. ```php options[$data['alpha2']] = Locale::getDisplayRegion("-{$data['alpha2']}", App::currentLocale()); } } } ``` -------------------------------- ### Create CMS Template Renderer Command (Bash) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Execute this Artisan command to generate a custom renderer class for CMS page templates. ```bash php artisan filament-cms:page-template-renderer ``` -------------------------------- ### Add Dynamic CPF/CNPJ Field (Filament 3.x PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-brazilian-cpfcnpj-field.md Creates a Filament TextInput field named 'cpf_cnpj' that dynamically applies a mask based on the input length using Filament's `RawJs` helper. It switches between CPF ('999.999.999-99') and CNPJ ('99.999.999/9999-99') formats and applies the 'cpf_ou_cnpj' validation rule provided by the installed package. ```php use Filament\Support\RawJs; TextInput::make('cpf_cnpj') ->mask(RawJs::make(<<<'JS' $input.length > 14 ? '99.999.999/9999-99' : '999.999.999-99' JS)) ->rule('cpf_ou_cnpj') ``` -------------------------------- ### Define Custom CSS Styles (CSS) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Imports the default Filament CSS and defines custom styles for various Filament components using Tailwind CSS directives (@apply) to customize fonts, colors, and layout for the sidebar, brand, and main content areas. ```css /*resources\css\app.css*/ @import "../../vendor/filament/filament/resources/css/app.css"; * { font-family: "Rubik", sans-serif; font-size: 1.02rem; } .filament-sidebar-nav { @apply bg-primary-800 bg-gradient-to-tl from-primary-600 to-primary-700 dark:bg-gray-800 dark:border-gray-700 dark:from-gray-800 dark:to-gray-800; } .filament-sidebar-nav .border-t { @apply border-primary-600; } .filament-sidebar-item { @apply text-white; } .filament-sidebar-item .inline-flex { @apply text-primary-50 bg-primary-700 dark:bg-gray-900 dark:text-white; } .filament-sidebar-group svg { @apply text-primary-300; } .tracking-wider { @apply text-sm text-primary-200; } .filament-brand { @apply text-primary-700; } .filament-main { @apply bg-primary-50 dark:bg-gray-900 dark:border-gray-700; } .filament-main-content { @apply text-gray-600 dark:text-gray-400; } ``` -------------------------------- ### Adding Filament Upgrade Command to Composer Scripts Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-easy-way-to-create-a-filament-theme-in-minutes.md Include the Filament upgrade Artisan command in the composer.json's post-update-cmd script. This ensures the command runs automatically after Composer updates, keeping Filament up-to-date. ```json "post-update-cmd": [ // ... "@php artisan filament:upgrade" ] ``` -------------------------------- ### Writing Post Resource Tests (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Defines a suite of Pest tests for the Post resource. It includes tests for viewing the index page, creating, editing, deleting posts, and testing access control for non-admin users. It uses `beforeEach` to authenticate as an admin user for most tests. ```php use App\Models\Post; use App\Models\User; use Livewire\Livewire; beforeEach(function () { $this->actingAs( User::where('is_admin', true)->first() ); }); it('has posts page', function () { Livewire::test()->assertCanSeeTableRecords( Post::limit(10)->get() ); }); it('can create posts', function () { Livewire::test()->assertPageActionExists('create'); }); it('can edit posts', function () { Livewire::test()->assertTableActionExists('edit'); }); it('can delete posts', function () { Livewire::test()->assertTableActionExists('delete'); }); it('cannot view posts', function () { $this->actingAs( User::where('is_admin', false)->first() ); Livewire::test()->assertStatus(403); }); ``` -------------------------------- ### Implementing FilamentUser Contract for Panel Access (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/danharrin-panel-403-in-production.md This PHP code snippet demonstrates how to make a User model compatible with Filament by implementing the FilamentUser contract. It includes the canAccessPanel method, which is used to determine if a user is authorized to access a specific Filament panel. The example authorization logic checks if the user's email ends with '@yourdomain.com' and if their email is verified. ```php email, '@yourdomain.com') && $this->hasVerifiedEmail(); } } ``` -------------------------------- ### Adding Filament Upgrade Command (JSON) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md Configures the `composer.json` file to automatically run the `filament:upgrade` Artisan command after Composer updates. This ensures Filament-specific updates are applied. ```json "post-update-cmd": [ // ... "@php artisan filament:upgrade" ] ``` -------------------------------- ### Overriding paginateTableQuery for Fast Pagination in FilamentPHP (PHP) Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/articles/danharrin-fast-table-pagination.md This PHP snippet demonstrates how to override the `paginateTableQuery` method in a FilamentPHP Livewire component (such as a List/Manage page or Relation Manager) to utilize the `fastPaginate` method provided by the `hammerstone/fast-paginate` package. It checks if 'all' records are requested and uses `count()` accordingly, otherwise it uses the standard records per page setting. This requires the `hammerstone/fast-paginate` package to be installed. ```php use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Builder; protected function paginateTableQuery(Builder $query): Paginator { return $query->fastPaginate(($this->getTableRecordsPerPage() === 'all') ? $query->count() : $this->getTableRecordsPerPage()); } ``` -------------------------------- ### Create New Filament CMS Data-type Page Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Generate the necessary files (page data, template, and Filament resource) for a new data-type page using the Artisan command. ```bash php artisan filament-cms:data-type-page Link ``` -------------------------------- ### Publish Filament CMS Vendor Views Source: https://github.com/filamentphp/filamentphp.com/blob/main/content/plugins/solution-forest-cms-website.md Use the Artisan command to publish the default vendor views for Filament CMS components, allowing customization. ```bash php artisan vendor:publish --tag=filament-cms-views ```