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
Php Units Of Measure Bundle

Php Units Of Measure Bundle Laravel Package

midnightluke/php-units-of-measure-bundle

Symfony bundle integrating the php-units-of-measure library, providing unit definitions and services to work with quantities, conversions, and formatting in your app. Adds simple configuration and DI wiring for unit-of-measure support.

View on GitHub
Deep Wiki
Context7

Provides a bundle wrapper around the "units of measure" library with useful form & doctrine types.

Frequently asked questions about Php Units Of Measure Bundle
Can I use this bundle in a Laravel project, or is it strictly for Symfony?
This bundle is Symfony-first but works in Laravel via Symfony’s bridge (e.g., symfony/flex). You’ll need to register the bundle in `AppKernel` or use a Laravel-compatible Symfony integration like `spatie/laravel-symfony-support`. Doctrine ORM works natively, but Eloquent users may need custom wrappers.
How do I install and configure this bundle in Laravel?
Run `composer require midnightluke/php-units-of-measure-bundle`, then register the bundle in `AppKernel` (Symfony) or use a Laravel-compatible bridge. Configure Doctrine types in `config/packages/doctrine.yaml` by mapping the provided types (e.g., `length`, `mass`) to your entity fields.
Does this bundle support custom units beyond the defaults (e.g., light-years)?
The bundle wraps the `php-units-of-measure` library, which supports SI and many derived units. Custom units require extending the underlying library or creating custom Doctrine types. Check the [php-units-of-measure docs](https://github.com/PhpUnitsOfMeasure/php-units-of-measure) for extensibility.
Will this bundle work with Laravel’s Eloquent ORM, or only Doctrine?
The bundle is designed for Doctrine ORM. For Eloquent, you’d need to create custom accessors/mutators or use a hybrid approach (e.g., store units as strings/enums in the DB and validate/convert in application logic). Consider `laravel-doctrine/orm` if you need full Doctrine support.
How do I handle form inputs for units (e.g., dropdowns for meters/kilometers)?
The bundle provides Symfony form types (e.g., `UnitType`). In Laravel, use `spatie/laravel-symfony-support` to integrate Symfony forms or build custom Blade components. For Laravel Collective forms, manually map the bundle’s unit options to your form fields.
What Laravel versions and PHP versions are supported?
The bundle requires PHP 7.4+ and Symfony 5.4+. Laravel compatibility depends on Symfony’s bridge (e.g., Laravel 8+ with `symfony/flex`). Check the [README](https://github.com/midnightLuke/php-units-of-measure-bundle) for updates, as Laravel-specific support may require community patches.
Are there performance concerns with using Doctrine types for units?
Doctrine types add minimal overhead for queries but may impact migrations if your schema isn’t normalized. Test in a staging environment to measure performance. For large datasets, consider caching unit conversions or using raw strings/enums with application-layer validation.
How do I migrate existing data stored as strings/enums to this bundle’s UnitType?
Use Doctrine migrations to update your schema, then write a data migration script to convert existing values. For example, replace `string` columns with `UnitType` and backfill with valid unit objects. Test thoroughly to avoid precision loss (e.g., `100cm` → `1m`).
Does this bundle conflict with Laravel’s built-in validation rules?
The bundle includes its own validators for unit conversions. To avoid conflicts, namespace your validation rules or disable Laravel’s conflicting rules (e.g., `Rule::in()`) for unit fields. Use the bundle’s validators explicitly in your form requests or controllers.
What alternatives exist for unit-of-measure support in Laravel?
For lightweight needs, use custom enums (e.g., `UnitEnum`) with Laravel’s validation. For full-featured solutions, consider `spatie/laravel-unit` (Laravel-native) or the underlying `php-units-of-measure` library directly. This bundle is ideal if you need Doctrine integration and Symfony form types.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor