I assume trial_ends_at is in your $dates array on the model?
https://laravel.com/docs/5.5/eloquent-mutators#date-mutators
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've created a date diff accessor in my User model to determine the number of days a user has left in their Cashier free trial. The method looks like this:
Model - returns null
public function getRemainingTrialDaysAttribute() {
return now()->diffInDays($this->trial_ends_at, false);
}
When I try and access this method in my controller it always returns null, however the same code when written directly in the controller will return the correct date.
Controller - returns integer (correct)
$this->trialDaysRemaining = now()->diffInDays($this->user->trial_ends_at, false);
Can anyone explain to me why it returns null when called as an accessor from the User model?
Please or to participate in this conversation.