Merge pull request #14795 from abrardev99/view-page-improve

Add missing section "Lifecycle hooks" for ViewRecord
This commit is contained in:
Dan Harrin
2024-11-14 08:46:14 +00:00
committed by GitHub
@@ -102,6 +102,29 @@ 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:
```php
use Filament\Resources\Pages\ViewRecord;
class ViewUser extends ViewRecord
{
// ...
protected function beforeFill(): void
{
// 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 disabled form fields are populated from the database. Not run on pages using an infolist.
}
}
```
## Authorization
For authorization, Filament will observe any [model policies](https://laravel.com/docs/authorization#creating-policies) that are registered in your app.