- How do I install Kavenegar Laravel and get started?
- Run `composer require kavenegar/laravel`, register the `ServiceProvider` and `Facade` in `config/app.php`, then publish the config with `php artisan vendor:publish`. Finally, add your API key to `config/kavenegar.php`. The package supports Laravel 4–10.
- Does this package support Laravel 10 and PHP 8.1+?
- Yes, the package officially supports Laravel 10, but some newer PHP features (like attributes) may require manual validation. Test thoroughly if using PHP 8.1+. The README recommends using the latest Laravel version for best compatibility.
- How do I send an SMS using the facade?
- Use `Kavenegar::send($recipient, $sender, $message, $parameters)` where `$recipient` is the phone number, `$sender` is your sender ID, and `$parameters` are optional placeholders (e.g., for OTPs). Example: `Kavenegar::send('1234567890', '1234', 'Your OTP: {otp}', ['otp' => $code]).`
- Can I use this package with Laravel queues for async SMS sending?
- No, the package doesn’t natively support queues. However, you can wrap facade calls in a `Queueable` job (e.g., `SendSmsJob`) to defer SMS sending. Example: `Kavenegar::dispatch(new SendSmsJob($recipient, $message));`
- How do I handle errors like rate limits (HTTP 429) or API failures?
- The package doesn’t translate Kavenegar’s HTTP errors into Laravel exceptions by default. You’ll need to catch exceptions manually (e.g., `try-catch`) or extend the facade to add retry logic. Check the underlying `kavenegar/php` SDK for error codes.
- Is there built-in logging for SMS delivery status?
- No, the package doesn’t include logging. You can manually log responses (e.g., success/failure) using Laravel’s `Log` facade or integrate with Monolog by extending the service provider to hook into the SDK’s callbacks.
- Can I mock Kavenegar responses in unit tests?
- Yes, you can mock the facade or the underlying `kavenegar/php` SDK. Use Laravel’s `MockFacade` or replace the service provider binding in tests. Example: `$this->app->instance('kavenegar', MockKavenegar::class);`
- What if I need to rotate my API key without downtime?
- Store the API key in environment variables (e.g., `.env`) instead of `config/kavenegar.php` for easier rotation. Use `config('kavenegar.apikey')` to fetch it dynamically, allowing you to update `.env` without republishing the config.
- Are there alternatives to this package for Laravel SMS integration?
- Yes, alternatives include `spatie/laravel-sms` (multi-provider) or direct integration with the `kavenegar/php` SDK. However, this package offers a Laravel-specific facade and publishable config, simplifying setup for Kavenegar users in Iran.
- How do I handle template-based SMS (e.g., predefined Kavenegar templates)?
- The package doesn’t natively support template IDs, but you can pass parameters to replace placeholders in the message string (e.g., `['otp' => $code]`). For advanced template management, extend the facade or use the raw `kavenegar/php` SDK methods.