Answer the question
In order to leave comments, you need to log in
How to change model field on update event?
There is a model update event assigned to updated.
I'm trying to update some model attributes on change but can't do it. What am I doing wrong?
class TagEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $tag;
public function __construct(Tag $tag)
{
$this->tag = $tag;
event(new SocketMessage($tag));
$geocode = new Geocode($tag->internal_latitude, $tag->internal_longitude);
$geocode->reverse();
$tag->airport = $geocode->airport_name;
$tag->city = $geocode->city;
$tag->country = $geocode->country;
$this->calculateDistance();
}
Answer the question
In order to leave comments, you need to log in
To change, you need to respond to the updating event. You can't change the model after the update
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question