- Does this package work with Laravel 10.x and PHP 8.2+?
- The package was last updated in 2020 and may not support Laravel 10.x or PHP 8.2+ out of the box. You’ll likely need to fork it, update dependencies, and test compatibility with newer Laravel versions. Check the underlying `cherif/algerian-mobile-phone-number` library for PHP version constraints.
- How do I cast a database column to an AlgerianMobilePhoneNumber value object in Eloquent?
- Add the `AlgerianMobilePhoneNumberCast` to your model’s `$casts` array. For example, `protected $casts = ['phone' => AlgerianMobilePhoneNumberCast::class];`. The package automatically handles conversion between strings (database) and the value object in your code.
- Can I use this package for request validation in Laravel?
- Yes. Use the `AlgerianMobilePhoneNumberRule` in your validation logic, like `'phone' => ['required', new AlgerianMobilePhoneNumberRule]`. It integrates directly with Laravel’s validator and Form Requests.
- What happens if I store an invalid number in the database?
- The package will throw a validation exception when retrieving the value object from the database if the stored string doesn’t match an Algerian mobile number format. Always validate input before saving to avoid runtime errors.
- Are there any limitations with carrier detection or international numbers?
- This package is specifically for Algerian mobile numbers and doesn’t handle international formats or carrier-specific logic beyond basic validation. If you need carrier detection, you may need to extend the underlying `cherif/algerian-mobile-phone-number` library or use a third-party service.
- How do I handle edge cases like ported numbers or VoIP services?
- The package relies on the core `cherif/algerian-mobile-phone-number` library, which may not account for all edge cases like ported numbers or VoIP. Test thoroughly with your dataset, and consider adding custom validation logic if needed.
- Is this package actively maintained? Should I fork it?
- The package hasn’t seen updates since 2020, so forking may be necessary to ensure compatibility with modern Laravel/PHP versions. If you plan to use it long-term, consider maintaining a private fork or contributing fixes upstream.
- Can I use this alongside other Laravel validation packages like `laravel-phone`?
- Yes, but ensure there are no conflicts in validation rules. This package is lightweight and focused on Algerian numbers, so it should coexist with other validation packages without issues.
- How do I test this package in my Laravel application?
- Write unit tests for validation rules using Laravel’s `Validator` facade and mock the underlying value object. For Eloquent casting, test model hydration/dehydration with both valid and invalid phone numbers to ensure proper behavior.
- What’s the best alternative if this package doesn’t meet my needs?
- For a more flexible solution, consider using a custom validation rule with regex and a carrier list, or explore libraries like `giggsey/libphonenumber-for-php` for broader international support. However, this package is ideal if you specifically need Algerian number validation with minimal setup.