SinghWithLaravel
5 months ago
566
19
Laravel

How can i write accessor for created_at or updated_at ?

Posted 5 months ago by SinghWithLaravel

I made two accessors like below code, but while fetching it is not showing what is being passed in accessors for created_at & updated.

   
    /**
     * This will change date according to timezone. 
     * @param String path
     */
    public function getCreatedAtAttribute($value)
    {
        return $this->changeDateFormUTCtoLocal($value);
    }

    /**
     * This will change date according to timezone. 
     * @param String path
     */
    public function getUpdatedAtAttribute($value)
    {
        return $this->changeDateFormUTCtoLocal($value);
    }

But this is not working. While other accessors are working which are following camelCase convention. Personally i assume it as an case issue. I think laravel assumes attributes as camelCase. What can be the solution ?

Please sign in or create an account to participate in this conversation.