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

Serializer

The MoneyBundle provides support for serializing Money\Money instances using either the Symfony Serializer component or the JMS Serializer (note, the JMSSerializerBundle must be installed to enable the serialization handler for the JMS serializer).

Below is an example of building a JSON response in a controller using the Symfony Serializer:

<?php

namespace App\Controller\API;

use Money\Money;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

final class MoneyCalculatorController extends AbstractController
{
    #[Route(path: '/api/money/add', name: 'app_api_add_money', methods: ['POST'])]
    public function apiAddValues(Request $request): JsonResponse
    {
        $firstValue = $request->request->getInt('first_value');
        $secondValue = $request->request->getInt('second_value');

        $addedValues = Money::USD($firstValue)->add(Money::USD($secondValue));

        return $this->json($addedValues);
    }
}

Below is an example of how a Money\Money instance is serialized into JSON format:

{
    "amount": "1000",
    "currency": "USD"
}
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.
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
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui