We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
When working with Laravel, you usually handle dates and times using the Carbon library. If you're using Laravel JSON resources to return structured API responses, you might wonder how Carbon instances are serialized into JSON.
By default, Laravel automatically converts Carbon instances to ISO 8601 formatted strings when they are included in a JSON resource. For example:
use Carbon\Carbon;
return Carbon::now()->toISOString();
This results in a string like:
2024-11-19T12:34:56.789000Z
The toISOString()
method ensures that your datetime values are formatted in a standard, widely-used format.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.