Level 51
You can use accessor when you get data from database
https://laravel.com/docs/5.3/eloquent-mutators#accessors-and-mutators
public function getYourDateAttribute()
{
return $this->your_date->format('Y');
}
2 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a timestamp field in my table. I only want to choose year for this field. Is there any way so that I can use the date function of php but only the years will be shown.
Please or to participate in this conversation.