- Can I use this package directly in Laravel, or is it only for Symfony?
- This package is built for Symfony but can integrate into Laravel with minor adjustments. Laravel’s service container and event system are compatible, though you may need to create a custom service provider or use composer overrides to resolve Symfony-specific dependencies like `symfony/event-dispatcher`. The DSN configuration (e.g., `freemobile://LOGIN:API_KEY@default?phone=PHONE`) works seamlessly with Laravel’s `.env` setup.
- How do I configure Free Mobile Notifier in Laravel to send SMS?
- Add the package via Composer (`composer require symfony/free-mobile-notifier`), then configure the DSN in your `.env` file: `FREE_MOBILE_DSN=freemobile://your_login:your_api_key@default?phone=your_phone`. Use Laravel’s `Notification` facade or Symfony’s `Notifier` component (if integrated) to send messages. Example: `Notifier::sendSms(new SmsMessage('Hello'), new FreeMobileTransport($dsn));`.
- What Laravel versions does this package support?
- The package itself is Symfony-focused, but Laravel 8.x, 9.x, and 10.x can integrate it with minimal effort. Ensure your Laravel version supports PHP 8.0+ (Symfony Notifier’s requirement). Test thoroughly with your Laravel version, as Symfony’s `EventDispatcher` or `HttpClient` may need Laravel-specific bindings. Check the Symfony Notifier docs for PHP version compatibility.
- How do I handle event-driven workflows (e.g., SmsSentEvent) in Laravel?
- Laravel’s event system differs from Symfony’s, so you’ll need a bridge. Create a Laravel event listener that triggers on `SmsSentEvent` or use a decorator pattern to wrap Symfony’s `EventDispatcher`. Alternatively, leverage Laravel’s `Bus` or `Queue` system to process events asynchronously. Example: `Event::listen(SmsSentEvent::class, function ($event) { Log::info('SMS sent:', $event->toArray()); });`.
- What happens if Free Mobile’s API fails? Can I fallback to email or another provider?
- The package doesn’t natively support fallback providers, but you can implement a custom solution. Use Laravel’s `Notification` facade to chain providers (e.g., try Free Mobile, then fallback to email or Twilio). Example: `try { Notifier::sendSms(...); } catch (Exception $e) { Mail::to($user)->send(new FallbackSmsEmail($message)); }`. Monitor failures with Laravel’s `failed_jobs` table or a custom log.
- Does this package support multi-provider SMS notifications (e.g., Twilio + Free Mobile)?
- No, this package is Free Mobile-specific. For multi-provider support, use Laravel’s `Notification` facade with multiple channels (e.g., `via(['mail', 'nexmo'])`). Alternatively, abstract the SMS logic into a custom service class that routes messages to different providers based on conditions like cost, region, or reliability. Symfony Notifier’s `Transport` interface can help standardize this.
- How do I test Free Mobile Notifier in Laravel’s PHPUnit tests?
- Mock the Symfony `Transport` or `HttpClient` using Laravel’s `Mockery` or PHPUnit’s `createMock`. Example: `$transport = Mockery::mock(TransportInterface::class)->shouldReceive('send')->once()->andReturn(true);`. For event testing, mock the `EventDispatcher` or use Laravel’s `Event` facade directly. Test DSN validation by overriding the `FreeMobileTransport` constructor in your tests.
- Are there any production concerns like rate limits or webhook security?
- Free Mobile’s API may have rate limits; implement Laravel’s `throttle` middleware or a custom rate limiter to avoid hits. For webhook security (if using Free Mobile’s callbacks), validate requests with Laravel’s `signed` routes or `verified` middleware. Log all API interactions to debug issues, and consider using Laravel’s `queue` system to batch or delay SMS sends during high traffic.
- What are the alternatives to this package for Laravel SMS notifications?
- For Laravel, consider `vonage/client` (formerly Nexmo) or `twilio/sdk` for global SMS support. If you need EU-specific providers, check `africastalking/sdk` or `plivo/plivo-php`. This package’s unique advantage is Free Mobile’s EU pricing and local number validation, ideal for French or EU-based apps. For Symfony users, `symfony/notifier` with other providers offers broader flexibility.
- How do I monitor SMS delivery status or errors in Laravel?
- Laravel’s `failed_jobs` table logs queued SMS failures if using queues. For real-time tracking, implement a custom log table or use Laravel’s `log` channel to record delivery events. Integrate with monitoring tools like Sentry or Datadog by extending the `SmsSentEvent` listener. Free Mobile’s API may also provide delivery reports; parse these via a webhook endpoint secured with Laravel’s `verified` middleware.