|
| 1 | +## Filament |
| 2 | +- Filament is by this application, check how and where to follow existing application conventions. |
| 3 | +- Filament is a Server-Driven UI (SDUI) framework for Laravel. It allows developers to define user interfaces in PHP using structured configuration objects. It is built on top of Livewire, Alpine.js, and Tailwind CSS. |
| 4 | +- You can use the `search-docs` tool to get information from the official Filament documentation when needed. This is very useful for Artisan command arguments, specific code examples, testing functionality, relationship management, and ensuring you're following idiomatic practices. |
| 5 | + |
| 6 | +### Artisan |
| 7 | +- You must use the Filament specific Artisan commands to create new files or components for Filament. You can find these with the `list-artisan-commands` tool, or with `php artisan` and the `--help` option. |
| 8 | +- Inspect the required options, always pass `--no-interaction`, and valid arguments for other options when applicable. |
| 9 | + |
| 10 | +### Filament's Core Features |
| 11 | +- Actions: Handle doing something within the application, often with a button or link. Actions encapsulate the UI, the interactive modal window, and the logic that should be executed when the modal window is submitted. They can be used anywhere in the UI and are commonly used to perform one-time actions like deleting a record, sending an email, or updating data in the database based on modal form input. |
| 12 | +- Forms: Dynamic forms rendered within other features, such as resources, action modals, table filters, and more. |
| 13 | +- Infolists: Read-only lists of data. |
| 14 | +- Notifications: Flash notifications displayed to users within the application. |
| 15 | +- Panels: The top-level container in Filament that can include all other features like pages, resources, forms, tables, notifications, actions, infolists, and widgets. |
| 16 | +- Resources: Static classes that are used to build CRUD interfaces for Eloquent models. Typically live in `app/Filament/Resources`. |
| 17 | +- Schemas: Represent components that define the structure and behavior of the UI, such as forms, tables, or lists. |
| 18 | +- Tables: Interactive tables with filtering, sorting, pagination, and more. |
| 19 | +- Widgets: Small component included within dashboards, often used for displaying data in charts, tables, or as a stat. |
| 20 | + |
| 21 | +### Relationships |
| 22 | +- Determine if you can use the `relationship()` method on form components when you need `options` for a select, checkbox, repeater, or when building a `Fieldset`: |
| 23 | +@verbatim |
| 24 | +<code-snippet name="Relationship example for Form Select" lang="php"> |
| 25 | +Forms\Components\Select::make('user_id') |
| 26 | + ->label('Author') |
| 27 | + ->relationship('author') |
| 28 | + ->required(), |
| 29 | +</code-snippet> |
| 30 | +@endverbatim |
| 31 | + |
| 32 | +### Testing |
| 33 | +- It's important to test Filament functionality for user satisfaction. |
| 34 | +- Ensure that you are authenticated to access the application within the test. |
| 35 | +- Filament uses Livewire, so start assertions with `livewire()` or `Livewire::test()`. |
| 36 | + |
| 37 | +### Example Tests |
| 38 | +@verbatim |
| 39 | +<code-snippet name="Filament Table Test" lang="php"> |
| 40 | + livewire(ListUsers::class) |
| 41 | + ->assertCanSeeTableRecords($users) |
| 42 | + ->searchTable($users->first()->name) |
| 43 | + ->assertCanSeeTableRecords($users->take(1)) |
| 44 | + ->assertCanNotSeeTableRecords($users->skip(1)) |
| 45 | + ->searchTable($users->last()->email) |
| 46 | + ->assertCanSeeTableRecords($users->take(-1)) |
| 47 | + ->assertCanNotSeeTableRecords($users->take($users->count() - 1)); |
| 48 | +</code-snippet> |
| 49 | + |
| 50 | +<code-snippet name="Filament Create Resource Test" lang="php"> |
| 51 | + livewire(CreateUser::class) |
| 52 | + ->fillForm([ |
| 53 | + 'name' => 'Howdy', |
| 54 | + |
| 55 | + ]) |
| 56 | + ->call('create') |
| 57 | + ->assertNotified() |
| 58 | + ->assertRedirect(); |
| 59 | + |
| 60 | + assertDatabaseHas(User::class, [ |
| 61 | + 'name' => 'Howdy', |
| 62 | + |
| 63 | + ]); |
| 64 | +</code-snippet> |
| 65 | + |
| 66 | +<code-snippet name="Testing Multiple Panels (setup())" lang="php"> |
| 67 | + use Filament\Facades\Filament; |
| 68 | + |
| 69 | + Filament::setCurrentPanel('app'); |
| 70 | +</code-snippet> |
| 71 | + |
| 72 | +<code-snippet name="Calling an Action in a Test" lang="php"> |
| 73 | + livewire(EditInvoice::class, [ |
| 74 | + 'invoice' => $invoice, |
| 75 | + ])->callAction('send'); |
| 76 | + |
| 77 | + expect($invoice->refresh())->isSent()->toBeTrue(); |
| 78 | +</code-snippet> |
| 79 | +@endverbatim |
0 commit comments