Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Money Bundle Laravel Package

babdev/money-bundle

View on GitHub
Deep Wiki
Context7

Twig

The MoneyBundle provides support for creating rendering Money instances within Twig (note, the TwigBundle must be installed to automatically enable the Twig extension).

Filters

money Filter

When rendering a Twig template, you can use the money filter with a Money instance to format the object into a string for display. Most of the formatters from the Money library are available using the $format parameter of the filter (the aggregate formatter is not supported).

The filter has the following additional optional arguments:

  • $format - An identifier for the formatter to use, all formatters use a snake case version of the formatter class without the "MoneyFormatter" suffix (i.e. to use the Bitcoin formatter the key name is "bitcoin"); this defaults to "intl_money"
  • $locale - The locale to use while formatting the Money instance, only supported with the intl formatters, defaults to the value of the kernel.default_locale parameter if one is not provided
  • $options - Additional options to configure the formatters, currently supported keys are "fraction_digits", "grouping_used", and "style" (note not all formatters support all options)

Below is a basic example of rendering the $tax_due property from an Invoice entity (which is typed as a Money instance), the default configuration will be used:

{{ invoice.tax_due|money }}

Below is an advanced example of rendering the $tax_due property, passing additional options through the filter

{{ invoice.tax_due|money('decimal', 'de', {fraction_digits: 0}) }}

Functions

money Function

When rendering a Twig template, you can use the money function to create a Money instance to use in a template.

You must provide an amount compatible with the Money class' constructor (i.e. an amount expressed in cents). The function also has an optional currency argument, and if omitted will use the default currency set in your application's configuration.

{# Creates a new Money instance in the default currency #}
{% set total = money(0) %}

{# Creates a new Money instance in the specified currency #}
{% set total = money(0, 'EUR') %}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager