Support the ongoing development of →
Eloquent Database
Last updated 2 years ago.

You can use Eloquent events

class Travel extends Model

    public static function boot() {

	static::creating( function( $model ) {
	} );

	static::updating( function( $model ) {
	} );

    protected function formatMyPoint() {
	$this->my_point = DB::raw('POINT(' . $this->x . ' ' . $this->y . ')');

pangodream liked this reply


Thanks for your reply!

I've used the saving event, that is fired on create and update and it works fine, but I need to avoid Eloquent trying to save this->x and this->y to database. I think I can do it with unset(this->x/y) but I will prefer a cleaner way.


Last updated 6 years ago.

Sign in to participate in this thread!


Your banner here too?

Abel abelcs Joined 11 Oct 2017


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.