Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MimisK's avatar
Level 12

Date of modification, in a specific field.

Good morning.

I have a "status" field in the database (Active, Inactive). How could I keep a modification date only for this field?

That is, to know how long a user has been "inactive".

Any suggestions - ideas? Thanks

0 likes
3 replies
Snapey's avatar

add a date time column, then create a mutator for your status. Set the datetime in the mutator according to your business logic whenever the status is set.

1 like
MimisK's avatar
MimisK
OP
Best Answer
Level 12

In case someone needs something similar:


 public function setStatusIdAttribute($value)
 {
        $this->attributes['status_id'] = $value ?? $value = 1;

        if($this->isDirty())
        {
            $this->attributes['status_updated_at'] = now();
        }
 }

@snapey, I don't know if that's exactly what you had in mind, but thank you.

Snapey's avatar

Pretty much. Not sure why you need the isDirty check?

Please or to participate in this conversation.