Laravel-46Elks is a SMS notification driver for Laravel Notifications, written to streamline the interaction between 46elks API and your Laravel application. For generic PHP usage, please check out php-46elks instead.
Install with composer
composer require tarre/laravel-46elks
Publish config
php artisan vendor:publish --tag="laravel-46elks"
Adjust config
Add this to your .env
file
e46ELKS_FROM=MyApp
e46ELKS_USERNAME=xxx
e46ELKS_PASSWORD=yyy
e46ELKS_DRY_RUN=false
e46ELKS_WHEN_DELIVERED=false
User model
class User Extends Model
{
use Notifiable;
public function routeNotificationFor46elks()
{
return '+46701474417'; // could also be an array of strings ['number1', 'number2'] etc
}
}
Notification
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Tarre\Laravel46Elks\Messages\SmsMessage;
class TestNotification extends Notification
{
use Queueable;
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['46elks'];
}
/**
* Send the message via 46elks
*
* @param mixed $notifiable
* @return SmsMessage
*/
public function to46elks($notifiable)
{
return (new SmsMessage)
->line('Hello ' . $notifiable->name)
->line('') // will produce new line
->line('Wsup?');
}
}
If you are using toMail
already, check out Piggybacking on Notifications toMail method
__construct(array $lines)
Alternative to->line('')
->line($line)
Add text message linefrom($senderId)
Overrides the .env filecc($e164Number)
Add more e164 recipientswhenDelivered($url)
Overrides the .env fileflash($state = true)
Flash SMS are shown immediately on the receivers phone and do not disappear until the receiver has confirmed the message. This feature is perfect for messages that really have to be read by the receiver.