- How do I install **zdenekdrahos/bn-php** in a Laravel project?
- Run `composer require zdenekdrahos/bn-php` in your project root. The package is dependency-free, so no additional setup is needed beyond autoloading. Laravel’s Composer autoloader will handle the rest automatically.
- Does this package support Laravel’s Eloquent models for BN validation?
- Yes, you can use Laravel’s model casting or accessors to validate and format BN values. For example, cast a field as a string and validate it with the package’s `validate()` method in a model’s `boot()` or `getAttribute()` methods.
- What Laravel versions does **bn-php** officially support?
- The package is designed for Laravel 8+ due to its reliance on modern PHP features like traits and Composer autoloading. Test thoroughly if using Laravel 7 or earlier, as some functionality may require adjustments.
- Can I use this for **Bengali numeral conversion** (e.g., ১২৩ → 123) in Laravel?
- No, this package focuses on **business number validation/parsing**, not Bengali numeral conversion. For Bengali numerals, consider packages like `shahriarNafein/arabic-to-english-numbers` or `bengali-numerals` instead.
- How do I handle BN values in Laravel database migrations?
- Store BN values as strings in text/varchar columns to avoid precision loss. Use Laravel’s `attribute casting` to convert between strings and BN objects in models. For example, cast a `price` field as `string` and validate it with the package.
- Will this package work with **Laravel’s query builder** for BN comparisons?
- No, the package doesn’t integrate directly with Laravel’s query builder. You’ll need to manually validate BN values in application logic before passing them to queries or use raw SQL with string comparisons.
- Are there any **performance concerns** when using BN validation in bulk operations?
- The package is lightweight, but if validating thousands of BN values, consider batching operations or caching validated results. Avoid real-time validation in loops where possible to minimize overhead.
- How do I **format BN values** consistently in API responses or Blade templates?
- Use the package’s `format()` method to standardize BN output. For APIs, return formatted strings (e.g., `response()->json(['bn' => $bn->format()])`). In Blade, use `@php echo $bn->format() @endphp` or a custom helper.
- What happens if I pass an **invalid BN** (e.g., letters, symbols) to the validator?
- The `validate()` method will throw an exception (e.g., `InvalidBusinessNumberException`). Catch it in your application logic and handle errors gracefully, such as returning a 422 response in Laravel APIs.
- Is there a **maintenance risk** with this package, given its low activity?
- Yes, the package appears unmaintained. Fork it on GitLab or maintain a local copy if it’s critical to your project. Alternatively, evaluate alternatives like `moneyphp/money` for financial BN handling or build a custom solution.