Home / Companies / Twilio / Blog / Post Details
Content Deep Dive

Create a Currency Data Type using Custom Casts in Laravel 7

Blog post from Twilio

Post Details
Company
Date Published
Author
Shane Rosenthal
Word Count
1,391
Company Posts That Month
59
Language
English
Hacker News Points
-
Post removed?
No
Summary

$php artisan make:model Subscription -m` creates a model found at `app\Subscription.php` and a migration located at `database\migrations\create_subscriptions_table`. The migration adds columns for `id`, `price`, `currency`, and timestamps. A route is added to retrieve the first subscription, and a new cast class called `Money` is created to handle currency data. The `Money` class implements the `CastsAttributes` interface and provides methods for getting and setting the value of the `price` attribute as a Money object, with options to customize the amount and currency. The `Subscription` model is updated to use the `Money` cast on the `price` attribute.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.