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

LiamA's avatar
Level 1

Date serialization in observer

instructions here demonstrate how to set pre Laravel 7 date format on a model: https://laravel.com/docs/7.x/upgrade#date-serialization

How can I do the same for a project observer?

0 likes
1 reply
MichalOravec's avatar

@liama Just change your format where you need it.

$date->format('Y-m-d H:i:s');

Or create accessor for it

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    /**
     * Get the user's first name.
     *
     * @param  string  $value
     * @return string
     */
    public function getSerializeCreatedAtAttribute($value)
    {
        return $this->created_at->format('Y-m-d H:i:s');
    }
}

After you can call it like

$project->serialize_created_at

Please or to participate in this conversation.