samedi 3 mars 2018

Why might diffForHumans be ignored in the Laravel5.5 model mutator?

I want to define an accessor for the created_at field. My code is:

public function getCreatedAtAttribute($value) {
    return $value->diffForHumans();
}

It throws an Call to a member function diffForHumans() on null error.

But $task->created_at->diffForHumans(); works fine in the view.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire