From c60a565375ac741bfd30f8bc9fd8acddc29f99f7 Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Thu, 14 Nov 2024 11:53:15 +0500 Subject: [PATCH 1/2] Add missing section for page hooks --- .../docs/03-resources/05-viewing-records.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/panels/docs/03-resources/05-viewing-records.md b/packages/panels/docs/03-resources/05-viewing-records.md index a98f93f57b..eda2c2820d 100644 --- a/packages/panels/docs/03-resources/05-viewing-records.md +++ b/packages/panels/docs/03-resources/05-viewing-records.md @@ -102,6 +102,30 @@ protected function mutateFormDataBeforeFill(array $data): array Alternatively, if you're viewing records in a modal action, check out the [Actions documentation](../../actions/prebuilt-actions/view#customizing-data-before-filling-the-form). +## Lifecycle hooks +Hooks may be used to execute code at various points within a page's lifecycle, like before a form is filled. To set up a hook, create a protected method on the View page class with the name of the hook: + +There are several available hooks for the View pages: + +```php +use Filament\Resources\Pages\ViewRecord; + +class ViewUser extends ViewRecord +{ + // ... + + protected function beforeFill(): void + { + // Runs before the form fields are populated from the database. + } + + protected function afterFill(): void + { + // Runs after the form fields are populated from the database. + } +} +``` + ## Authorization For authorization, Filament will observe any [model policies](https://laravel.com/docs/authorization#creating-policies) that are registered in your app. From c5dac71bd3f66a66e2890aa4328f8d95d50c6287 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Thu, 14 Nov 2024 08:46:07 +0000 Subject: [PATCH 2/2] Update 05-viewing-records.md --- packages/panels/docs/03-resources/05-viewing-records.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/panels/docs/03-resources/05-viewing-records.md b/packages/panels/docs/03-resources/05-viewing-records.md index eda2c2820d..e1526bf9be 100644 --- a/packages/panels/docs/03-resources/05-viewing-records.md +++ b/packages/panels/docs/03-resources/05-viewing-records.md @@ -103,9 +103,8 @@ protected function mutateFormDataBeforeFill(array $data): array Alternatively, if you're viewing records in a modal action, check out the [Actions documentation](../../actions/prebuilt-actions/view#customizing-data-before-filling-the-form). ## Lifecycle hooks -Hooks may be used to execute code at various points within a page's lifecycle, like before a form is filled. To set up a hook, create a protected method on the View page class with the name of the hook: -There are several available hooks for the View pages: +Hooks may be used to execute code at various points within a page's lifecycle, like before a form is filled. To set up a hook, create a protected method on the View page class with the name of the hook: ```php use Filament\Resources\Pages\ViewRecord; @@ -116,12 +115,12 @@ class ViewUser extends ViewRecord protected function beforeFill(): void { - // Runs before the form fields are populated from the database. + // Runs before the disabled form fields are populated from the database. Not run on pages using an infolist. } protected function afterFill(): void { - // Runs after the form fields are populated from the database. + // Runs after the disabled form fields are populated from the database. Not run on pages using an infolist. } } ```