This doesn't seem to work anymore. It might have to do with Laravel 5.1, but I can't seem to find out what's going wrong. The call in bootstrap/app.php simply doesn't change anything; it's back to the Laravel defaults.
I was able to get a workaround for this by creating a few mutators on an intermediate abstract class (ModelA extends ModelB) called:
abstract class ModelB extends Model
{
/**
* Converts the created_at to Atom-format
*
* @return string
*/
public function getCreatedAtAtomAttribute()
{
return $this->created_at->toAtomString();
}
/**
* Converts the updated_at to Atom-format
*
* @return string
*/
public function getUpdatedAtAtomAttribute()
{
return $this->updated_at->toAtomString();
}
}
This allows you to call $modelA->created_at_atom (or something similar) and maintains the created_at attribute as it works currently.
use Illuminate\Support\Carbon;
public function boot()
{
Carbon::serializeUsing(function ($carbon) {
return $carbon->format('Y-m-d H:i:s e'); // Customize the format as per your requirements
});
}
This will set the default date format for Carbon whenever it is serialized, including when your models are converted to JSON in the context of a REST API response.