Search code examples
phplaravelapidatelaravel-5.5

Changing Date format through cast and date property of laravel not working on server


I am building an API using laravel in which I need to show timestamps in d.m.Y g:i a format. I am using

protected $dates = [ 'created_on', 'modified_on'];

protected $casts = [
    'created_on' => 'datetime:d.m.Y g:i a',
    'modified_on' => 'datetime:d.m.Y g:i a',
];

I have tried this code on my local and it was working fine I can see the changed date format in response of my API's related to the model but when I am testing it on my server, I am getting the Y-m-d format. Where I am doing wrong, Thanks for help.


Solution

  • Ok, So after checking for every error on earth, I have found that the issue was, in my local I was using laravel 5.6 but on my server I was using laravel 5.5 . So basically it was all laravel version issue. This trick is definitely best for those who wants dates field in the desired format without changing the original format.