A lightweight PHP currency casting package for turning raw money values into consistent, predictable currency objects and back again. It works cleanly in Laravel, but it’s not limited to Laravel applications.
What it does
laravel-currency-cast solves a simple but annoying problem: money data often arrives as strings, integers, denials, or mixed formats, and those values can easily drift between layers of an application.
This package gives developers a consistent way to:
- Cast incoming values into a currency-aware representation.
- Format money values for display without repeating formatting logic everywhere.
- Keep raw storage and human-readable output separate.
- Use the same casting logic in Laravel models or plain PHP code.
It’s designed to say small and practical, without forcing a heavy money-handling framework into your app.
Why I build it
Currency handling tends to get messy fast. Different APIs send different formats, database storage can vary by project, and presentation logic often leaks into domain code.
I built this package to provide a reusable currency casting layer that can be dropped into:
- Laravel applications.
- Standalone PHP projects.
- Internal tools and services.
- API integrations that need reliable money normalisation.
The aim is consistency: one place to define how a currency value should be interpreted, stored, and displayed.
Key features include;
- Framework-agnostic core:
- Can be used outside of Laravel.
- Useful in plain PHP applications and libraries.
- Laravel-friendly casting:
- Works naturally with Laravel’s model casting system.
- Easy to plug into models where you need money fields handled cleanly.
- Predictable value handling:
- Normalises currency input before it reaches your business logic.
- Helps avoid scattered formatting and parsing code.
- Reusable across layers:
- Same package can support domain logic, persistence, and presentation.
Example use cases
This package is useful when you need to:
- Store amounts consistently in a database.
- Convert API responses into a currency object or cast.
- Display values in a standard format across your app.
- Avoid reimplementing currency formatting in multiple places.
- Share the same money-handling logic across Laravel and non-Laravel projects.
Example concept
In a Laravel model, a currency field can be cast so the value is always handled in a consistent way:
use AyupCreative\Casts\Currency\Currency;
class Product extends Model
{
protected $casts = [
'price' => Currency::class,
];
}In a standalone PHP context, the same logic can be used to normalise a value before saving it or passing it to another service.
What makes it useful
The package itself is intentionally focused. It does not try to be a complete accounting system or a full financial library. It does one job: currency casting and normalisation, in a way that works both inside and outside of Laravel.
That makes it a good fit for:
- SaaS applications of pricing fields.
- Order and invoice systems.
- Internal admin tools.
- API-driven products where money formats are inconsistent.