Downloads
Stars
Version
This package makes it easy to send SMS notifications for some sms providers with Laravel 5.8.
Supported SMS providers:
Add SmsNotification package to your Laravel project via composer:
composer required yudina/laravel-sms
Then publish configuration file:
php artisan vendor:publish --provider="Yudina\LaravelSms\SmsSenderServiceProvider"
Add the environment variables to your config/services.php:
// config/services.php
...
'default' => env('SMS_PROVIDER', 'smscru'),
'providers' => [
'smsru' => [
'api_id' => env('SMSRU_API_ID')
],
'smscru' => [
'login' => env('SMSCRU_LOGIN'),
'password' => env('SMSCRU_PASSWORD'),
'sender' => env('SMSCRU_SENDER')
],
...
]
...
Add your necessary keys to your .env:
// .env
SMSRU_API_ID=
...
Now you can use the channel in your via()
method inside the notification:
use Yudina\LaravelSms\SmsSenderChannel;
use Yudina\LaravelSms\SmsSenderMessage;
use Illuminate\Notifications\Notification;
class CodeGenerationNotification extends Notification
{
public function via($notifiable)
{
return [SmsSenderChannel::class];
}
public function toSms($notifiable)
{
$message = 'Activation code: ' . $this->generateCode(6);
return new SmsSenderMessage($message);
}
private function generateCode(int $length): string
{
$result = '';
for($i = 0; $i < $length; $i++)
$result .= mt_rand(0, 9);
return $result;
}
}