filament icon indicating copy to clipboard operation
filament copied to clipboard

Filament Panel Feature Breaks with Geometry Type Column Containing POINT Values

Open matheusjohannaraujo opened this issue 1 year ago • 1 comments

Package

filament/filament

Package Version

v3.2.93

Laravel Version

v10.48.16

Livewire Version

v3.5.2

PHP Version

v8.2.12

Problem description

When a column in the database is of type geometry, the Filament panel feature breaks (it's not possible to visualize the record).

When I fill the column with NULL value, it works fine, but when I fill it with the POINT value containing Latitude and Longitude, it stops working.

Expected behavior

I expected to be able to visualize the record.

View record in table

image

Steps to reproduce

Create Model and Migration

php82 artisan make:model Coleta --migration

Migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('coletas', function (Blueprint $table) {
            $table->id();

            $table->string('name');

            $table->geometry('geo')->nullable();

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('coletas');
    }
};

Model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Coleta extends Model
{
    use HasFactory;

    protected $table = 'coletas';

    protected $fillable = [
        'id',
	'name',
        'geo'
    ];

}

Seeder

$coleta = new \App\Models\Coleta();
$coleta->name = 'Test';
$coleta->geo = \Illuminate\Support\Facades\DB::raw('POINT(46.646748, 24.562727)');
$coleta->save();

Create Resource

php artisan make:filament-resource Coleta --generate

Resource

<?php

namespace App\Filament\Resources;

use App\Filament\Resources\ColetaResource\Pages;
use App\Filament\Resources\ColetaResource\RelationManagers;
use App\Models\Coleta;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class ColetaResource extends Resource
{
    protected static ?string $model = Coleta::class;

    protected static ?string $navigationIcon = 'heroicon-o-chevron-double-right';

    protected static ?string $navigationLabel = 'Coletas';

    protected static ?string $navigationGroup = 'Reciclagem';

    protected static ?string $modelLabel = 'Coleta';

    protected static ?string $pluralModelLabel = 'Coletas';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->label('Name')
                    ->required(),
            ])->columns(1);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('id')
                    ->label("#")
                    ->sortable(),
                Tables\Columns\TextColumn::make('name')
                    ->label('name'),
                Tables\Columns\TextColumn::make('created_at')
                    ->label("Criado em")
                    ->dateTime("d/m/Y H:i:s")
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: false),
                Tables\Columns\TextColumn::make('updated_at')
                    ->label("Atualizado em")
                    ->dateTime("d/m/Y H:i:s")
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\ActionGroup::make([
                    Tables\Actions\ViewAction::make(),
                    Tables\Actions\EditAction::make(),
                    //Tables\Actions\DeleteAction::make(),
                ]),
            ])
            ->bulkActions([
                /*Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),*/]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListColetas::route('/'),
            'create' => Pages\CreateColeta::route('/create'),
            'edit' => Pages\EditColeta::route('/{record}/edit'),
        ];
    }

}

Record in Table

image

Console Browser Error

image

Column geo in MySQL PhpMyAdmin

image

Column geo with value POINT (lat, lng) in MySQL PhpMyAdmin

image

Reproduction repository (issue will be closed if this is not valid)

https://github.com/matheusjohannaraujo/bug-template-laravel-filament/

Relevant log output

No error appears in laravel.log

matheusjohannaraujo avatar Jul 13 '24 18:07 matheusjohannaraujo

I have a very similar issue with Laravel Point column. Laravel: v10.48.20 Filament: v3.2.98 Livewire: v3.5.4 Migration:

$table->point('location')->nullable();

Factory:

'location' => \DB::raw("ST_GeomFromText('POINT(" . fake()->latitude . " " . fake()->longitude . ")')"),

The Filament Panel breaks when we try to edit any existing record having Point data. It logs no error/exception in the Laravel log. Just a blank screen in the browser with livewire js exceptions image

ravimisra avatar Aug 10 '24 12:08 ravimisra