1. Go to this page and download the library: Download alhaji-aki/laravel-sms library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alhaji-aki / laravel-sms example snippets
return [
/*
|--------------------------------------------------------------------------
| Default Sender
|--------------------------------------------------------------------------
|
| This option controls the default sms sender that is used to send all text
| messages unless another sender is explicitly specified when sending
| the message. All additional senders can be configured within the
| "senders" array. Examples of each type of senders are provided.
|
*/
'default' => env('SMS_SENDER', 'log'),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all text messages sent by your application to be sent from
| the same address. Here you may specify a name and address that is
| used globally for all messages that are sent by your application.
|
*/
'from' => env('SMS_FROM_NAME', 'Example'),
/*
|--------------------------------------------------------------------------
| Sender Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the senders used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application 'sender' => 'roundrobin',
'senders' => [
'log',
'array',
],
],
],
];
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the SMS channel.
*
* @param \Illuminate\Notifications\Notification $notification
* @return string
*/
public function routeNotificationForSms($notification)
{
return $this->phone_number;
}
}
use AlhajiAki\Sms\Notification\Messages\SmsMessage;
use Illuminate\Notifications\Notification;
class AccountApproved extends Notification
{
public function via($notifiable)
{
return ['sms'];
}
public function toSms($notifiable)
{
return (new SmsMessage())
->message("Hello sms notification channel");
}
}
use AlhajiAki\Sms\Sms;
Sms::send('Hello sms facade', '+3112345678');
use AlhajiAki\Sms\Sms;
Sms::sender('slack')->send('Hello sms facade', '+3112345678');
use AlhajiAki\Sms\Sms;
/**
* Bootstrap any application services.
*/
public function boot(): void
{
if ($this->app->environment('local')) {
Sms::alwaysTo('+3212345678');
}
}
use AlhajiAki\Sms\Events\SmsMessageSending;
// use AlhajiAki\Sms\Events\SmsMessageSent;
class LogMessage
{
/**
*Handle the given event.
*/
public function handle(SmsMessageSending $event): void
{
// ...
}
}
use AlhajiAki\Sms\SentMessage;
use AlhajiAki\Sms\TextMessage;
class TwilioSender implements SenderInterface
{
/**
* Create a new Twilio sender instance.
*/
public function __construct(protected array $config) {
}
/**
* {@inheritdoc}
*/
public function send(TextMessage $message): ?SentMessage
{
// Implement the logic to send SMS via your custom sender
}
/**
* Get the string representation of the sender.
*/
public function __toString(): string
{
return 'twilio';
}
}
use App\Sms\TwilioSender;
use AlhajiAki\Sms\Sms;
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Sms::extend('twilio', function (array $config = []) {
return new TwilioSender(/* ... */);
});
}