Eloquent `point` field type data triggers "Unexpected end of JSON input"

Is anyone using the point Eloquent field/attribute type in any of their models that have Filament resources? I've a resource that makes use of this which is failing with an "Unexpected end of JSON input" console error when attempting to view/edit a model which contains encoded point data. Attempting to create a new instance of the model initially works as expected, up until the point that the newly created model with the encoded data present is loaded. Dropping the database column and disabling the custom model setters that set the data based on field inputs resolves the issue, so it would seem as first glance to be related to the way the encoded point data is handled by the JSON encoder. As such, I'm wondering if anyone has encountered anything similar before I go bug hunting/try and create a stripped back project to illustrate the issue. I suspect this may be a Livewire v3 issue rather than a Filament one, but I thought I'd ask here first.
7 Replies
toeknee
toeknee14mo ago
Is the column a json column? Or is the json being truncated on save
John Parker
John ParkerOP14mo ago
It's a point column, which is a specific thing, at least in MySQL/MariaDB and (I'm guessing) PostgreSQL. The database migration is…
public function up(): void
{
Schema::create('table_name', function (Blueprint $table) {
$table->id();

$table->point('location')->spatialIndex();
});
}
public function up(): void
{
Schema::create('table_name', function (Blueprint $table) {
$table->id();

$table->point('location')->spatialIndex();
});
}
https://laravel.com/docs/10.x/migrations#column-method-point @toeknee Unless of course you mean the Filament Resource column, in which case that model attribute isn't used within Filament. (It's effectively controlled by a pair of custom setters.) However, the probiem is that the very existence of spatial data in the field is breaking Livewire/Filament with the aforementioned "Unexpected end of JSON input" error. I'm almost tempted to dig into the config to ensure the database connection encoding is correct, etc. but none of this has changed from the Livewire v2/Filament v2 version, hence it looks very much like it's a v3 specific issue. To confirm, setting the location attribute as hidden via $hidden = [ 'location' ]; in the model resolves the issue.
Ramon.vV
Ramon.vV2w ago
Experiencing the same error here, adding a location column with point data to any table breaks the edit and view forms for those records, even if the column isn't added to either form. @John Parker Have you gotten any further in finding the cause of this issue?
John Parker
John ParkerOP2w ago
I’m afraid not - I just lived with the “hidden” workaround.
Ramon.vV
Ramon.vV2w ago
Looks like that resolves the issue for me as well
Firebat
Firebat2w ago
i don't know if this would help but, im using a filament plugin for googlemaps and the guy behind made a work around to submit a point to the google api using computed attributtes he probably faced the same problem, and decided to go with this route
Ramon.vV
Ramon.vV2w ago
For me it's not a problem since I calculate the point from the lat/lon values I have locally and once it's done it never has to change again. That sounds like a good workaround though
Want results from more Discord servers?
Add your server