I need to add an extra attribute to my laravel model without using get Attribute. i want to get created_at attribute in both default and custom format.
default : created_at : 2018-07-25 15:38:56
second: 10 Days Ago
if i use getCreatedAtAttribute() it changes the default attribute.
In your model, add this:
protected $appends = ['readable_created_at'];
public function getReadableCreatedAtAttribute()
{
return $this->created_at; //or however you want to manipulate it
}
After which, you can access it like normal, e.g. $user->readable_created_at
.
Read more at the Laravel Doc here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With