Skip to content

Geometry fields are passed as Expression during Eloquent model event are fired. #87

Closed
@RomainMazB

Description

Hi!

During the insert, the library operate in three steps:

  1. It caches all the original geometries attributes as their defined type (a point as Point, and so on...) and convert all geometries as Expression.
  2. It performs insert using the eloquent performInsert method
  3. It refills the model attributes as their original states

https://github.com/clickbar/laravel-magellan/blob/main/src/Database/Eloquent/HasPostgisColumns.php#L116-L118

The problem here is that if you use the laravel eloquent model event:

class Person
{
    use \Clickbar\Magellan\Database\Eloquent\HasPostgisColumns;

    /** @var string[] */
    protected $postgisColumns = [
        'location' => [
            'type' => 'geometry',
            'srid' => 4326
        ]
    ];
    
    protected $dispatchesEvents = [
        'created' => \App\Events\Person\Created::class
    ];
}

The event is dispatched from the eloquent performInsert call, meaning it's called with all the geometries attributes as Expression and not as Point.

I'll investigate if there is some kind of hook inside the Eloquent model event dispatcher to see if this could be fixed properly.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions