Skip to content

Commit 8212b2b

Browse files
authored
fix: Non-UTF8 column data docs & command notice (#20135)
1 parent 28a7f5a commit 8212b2b

24 files changed

Lines changed: 235 additions & 12 deletions

File tree

docs/03-resources/01-overview.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,3 +672,15 @@ protected function mutateFormDataBeforeFill(array $data): array
672672
```
673673

674674
In this example, we remove the `is_admin` attribute from JavaScript, as it's not being used by the form.
675+
676+
<Aside variant="warning">
677+
Adding a column to `$hidden` is required, not just recommended, when it contains binary data that is not valid UTF-8, such as a `geometry`, `point`, or `blob` column. Since Filament exposes model attributes to JavaScript, these values are sent to the browser as part of the Livewire request, but they cannot be serialized to JSON. This causes the page to fail to load, often with a blank screen and no error in the Laravel log.
678+
679+
Adding such columns to [the `$hidden` array](https://laravel.com/docs/eloquent-serialization#hiding-attributes-from-json) on your model excludes them from its array and JSON representations, resolving the issue:
680+
681+
```php
682+
protected $hidden = ['location'];
683+
```
684+
685+
If you need to work with the value, expose it through an [accessor](https://laravel.com/docs/eloquent-mutators#defining-an-accessor) instead of the raw column.
686+
</Aside>

docs/12-components/02-form.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ public function mount(Post $post): void
160160

161161
It's important that you use the `$this->form->fill()` method instead of assigning the data directly to the `$this->data` property. This is because the post's data needs to be internally transformed into a useful format before being stored.
162162

163+
<Aside variant="warning">
164+
The data you pass to `fill()` is exposed to JavaScript as part of the Livewire request. If your model has a column containing binary data that is not valid UTF-8, such as a `geometry`, `point`, or `blob` column, it cannot be serialized to JSON and the page will fail to load, often with a blank screen and no error in the Laravel log.
165+
166+
To resolve this, add the column to [the `$hidden` array](https://laravel.com/docs/eloquent-serialization#hiding-attributes-from-json) on your model, which excludes it from `attributesToArray()`:
167+
168+
```php
169+
protected $hidden = ['location'];
170+
```
171+
</Aside>
172+
163173
## Setting a form model
164174

165175
Giving the `$form` access to a model is useful for a few reasons:

packages/actions/docs/05-edit.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Edit action
33
---
44
import AutoScreenshot from "@components/AutoScreenshot.astro"
5+
import Aside from "@components/Aside.astro"
56
import UtilityInjection from "@components/UtilityInjection.astro"
67

78
## Introduction
@@ -40,6 +41,18 @@ EditAction::make()
4041

4142
<UtilityInjection set="actions" version="4.x">As well as `$data`, the `mutateRecordDataUsing()` function can inject various utilities as parameters.</UtilityInjection>
4243

44+
<Aside variant="warning">
45+
Filament fills the form using the record's array representation, which is sent to the browser as part of the Livewire request. If your model has a column containing binary data that is not valid UTF-8, such as a `geometry`, `point`, or `blob` column, it cannot be serialized to JSON and the modal will fail to open, often with no error in the Laravel log.
46+
47+
To resolve this, add the column to [the `$hidden` array](https://laravel.com/docs/eloquent-serialization#hiding-attributes-from-json) on your model, which excludes it from the model's array and JSON representations:
48+
49+
```php
50+
protected $hidden = ['location'];
51+
```
52+
53+
This applies equally to the [View](view) and [Replicate](replicate) actions.
54+
</Aside>
55+
4356
## Customizing data before saving
4457

4558
Sometimes, you may wish to modify form data before it is finally saved to the database. To do this, you may use the `mutateDataUsing()` method, which has access to the `$data` as an array, and returns the modified version:

packages/forms/src/Commands/FileGenerators/Concerns/CanGenerateModelForms.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public function getFormComponents(?string $model = null, array $exceptColumns =
8585

8686
$type = $this->parseColumnType($column);
8787

88+
if (! $this->canGenerateSchemaComponentForColumnType($type)) {
89+
$this->recordSkippedColumn($model, $column);
90+
91+
continue;
92+
}
93+
8894
$componentData = [];
8995

9096
$componentData['type'] = match (true) {

packages/forms/src/Commands/FileGenerators/FormSchemaClassGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
use Filament\Schemas\Schema;
77
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
88
use Filament\Support\Commands\FileGenerators\ClassGenerator;
9+
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
910
use Illuminate\Database\Eloquent\Model;
1011
use Nette\PhpGenerator\ClassType;
1112
use Nette\PhpGenerator\Method;
1213

13-
class FormSchemaClassGenerator extends ClassGenerator
14+
class FormSchemaClassGenerator extends ClassGenerator implements HasSkippedColumns
1415
{
1516
use CanGenerateModelForms;
1617
use CanReadModelSchemas;

packages/forms/src/Commands/FileGenerators/LivewireFormComponentClassGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Filament\Schemas\Schema;
1111
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
1212
use Filament\Support\Commands\FileGenerators\ClassGenerator;
13+
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
1314
use Illuminate\Contracts\View\View;
1415
use Illuminate\Database\Eloquent\Model;
1516
use Livewire\Component;
@@ -19,7 +20,7 @@
1920
use Nette\PhpGenerator\Property;
2021
use Nette\PhpGenerator\TraitUse;
2122

22-
class LivewireFormComponentClassGenerator extends ClassGenerator
23+
class LivewireFormComponentClassGenerator extends ClassGenerator implements HasSkippedColumns
2324
{
2425
use CanGenerateModelForms;
2526
use CanReadModelSchemas;

packages/infolists/src/Commands/FileGenerators/Concerns/CanGenerateModelInfolists.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public function getInfolistComponents(?string $model = null, array $exceptColumn
5555

5656
$type = $this->parseColumnType($column);
5757

58+
if (! $this->canGenerateSchemaComponentForColumnType($type)) {
59+
$this->recordSkippedColumn($model, $column);
60+
61+
continue;
62+
}
63+
5864
if (in_array($type['name'], [
5965
'json',
6066
])) {

packages/panels/src/Commands/FileGenerators/Resources/Pages/ResourceManageRelatedRecordsPageClassGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Filament\Schemas\Schema;
1212
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
1313
use Filament\Support\Commands\FileGenerators\ClassGenerator;
14+
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
1415
use Filament\Support\Icons\Heroicon;
1516
use Filament\Tables\Table;
1617
use Illuminate\Database\Eloquent\Model;
@@ -25,7 +26,7 @@
2526
use Nette\PhpGenerator\Method;
2627
use Nette\PhpGenerator\Property;
2728

28-
class ResourceManageRelatedRecordsPageClassGenerator extends ClassGenerator
29+
class ResourceManageRelatedRecordsPageClassGenerator extends ClassGenerator implements HasSkippedColumns
2930
{
3031
use CanGenerateResourceForms;
3132
use CanGenerateResourceProperty;

packages/panels/src/Commands/FileGenerators/Resources/RelationManagerClassGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Filament\Schemas\Schema;
1111
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
1212
use Filament\Support\Commands\FileGenerators\ClassGenerator;
13+
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
1314
use Filament\Tables\Table;
1415
use Illuminate\Database\Eloquent\Model;
1516
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@@ -23,7 +24,7 @@
2324
use Nette\PhpGenerator\Method;
2425
use Nette\PhpGenerator\Property;
2526

26-
class RelationManagerClassGenerator extends ClassGenerator
27+
class RelationManagerClassGenerator extends ClassGenerator implements HasSkippedColumns
2728
{
2829
use CanGenerateResourceForms;
2930
use CanGenerateResourceInfolists;

packages/panels/src/Commands/FileGenerators/Resources/ResourceClassGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Filament\Schemas\Schema;
1313
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
1414
use Filament\Support\Commands\FileGenerators\ClassGenerator;
15+
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
1516
use Filament\Support\Icons\Heroicon;
1617
use Filament\Tables\Table;
1718
use Illuminate\Database\Eloquent\Builder;
@@ -24,7 +25,7 @@
2425
use Nette\PhpGenerator\Method;
2526
use Nette\PhpGenerator\Property;
2627

27-
class ResourceClassGenerator extends ClassGenerator
28+
class ResourceClassGenerator extends ClassGenerator implements HasSkippedColumns
2829
{
2930
use CanGenerateResourceForms;
3031
use CanGenerateResourceInfolists;

0 commit comments

Comments
 (0)