Download the PHP package alhaji-aki/laravel-sms without Composer
On this page you can find all versions of the php package alhaji-aki/laravel-sms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alhaji-aki/laravel-sms
More information about alhaji-aki/laravel-sms
Files in alhaji-aki/laravel-sms
Package laravel-sms
Short Description A package that allows developers integrate sms providers and provide a common api to send their users messages.
License MIT
Homepage https://github.com/alhaji-aki/laravel-sms
Informations about the package laravel-sms
Laravel SMS
Laravel SMS is a package that provides a simple and flexible way to send SMS messages from your Laravel application. It supports multiple SMS providers and allows you to easily switch between them.
Installation
You can install the package via composer by running:
Configuration
After the installation has completed, the package will automatically register itself. Run the following to publish the config file
This will create a sms.php
file in your config folder where you can configure your SMS providers and other settings. The config file looks like this
The package comes preconfigured for sms providers like Hellio, Wigal, Slack, Log and array.
Failover Configuration
The failover mechanism allows you to define multiple providers to be used in case the primary provider fails. The configuration array for your application's failover sender should contain an array of senders that reference the order in which configured senders should be chosen for delivery:
Once your failover sender has been defined, you should set this sender as the default sender used by your application by specifying its name as the value of the default
configuration key within your application's sms
configuration file:
Round Robin Configuration
The roundrobin
sender allows you to distribute SMS sending across multiple senders to balance the load. To get started, define a sender within your application's sms
configuration file that uses the roundrobin
sender. The configuration array for your application's roundrobin
sender should contain an array of senders
that reference which configured senders should be used for delivery:
Setting the FROM
This package allows you to set the from
address of your sms in two ways the global way or per sender.
Using a Global from
Address
If your application uses the same "from" address for all of its sms, it can become cumbersome to add it to each sender. Instead, you may specify a global "from" address in your config/sms.php
configuration file. This address will be used if no other "from" address is specified when sending the sms:
Using Sender Level from
Address
If each sender has their own "from" address, you can specify it in the sender's configuration in the config/sms.php
configuration file. This address will be used if no other "from" address is specified when sending the sms:
You can also specify a from
address when sending the sms. The from
specified when sending the message takes precedence over the from
set at the Sender level in the sender's configuration. This also takes precedence over the global from
set in the config/sms.php
configuration file.
Usage
In a notification class
To use this package in your notifications, in your notifiable model, make sure to include a routeNotificationForSms()
method, which returns a phone number. Like below:
Then in your notification class can use the channel sms
in your via()
method:
The \AlhajiAki\Sms\Notification\Messages\SmsMessage
class provides the following method
sender()
: Use this method when you want to change the default sender set in theconfig/sms.php
file. This method accepts a string or null.from()
: Use this method to set thefrom
address of the message. This method accepts a string.data()
: The data method provides a means for sending data that might be useful to sender class at the point of sending a message. This could be used to set the message type or any relevant information needed to be able to send the sms by sender.
Using the facade
The package provides an Sms
facade which can be used to send sms like below:
If you want to use a different sender to send an sms, you can do so like below:
The send()
method of accepts 4 parameters explained below:
$message
: The message to be sent. This is a string.$to
: The receipient(s) fo the message. This is either a string or an array.$from
: The from address. This is a string or null. If it is not provided the sender'sfrom
or the globalfrom
set in theconfig/sms.php
file will be used.$data
: The data to be sent to the sender
Sms and Local Development
When developing an application that sends sms, you probably don't want to actually send messages to live phone numbers. This package provides several ways to "disable" the actual sending of messages during local development.
Log Driver
Instead of sending your messages, the log sender driver will write all messages to your log files for inspection. Typically, this driver would only be used during local development. For more information on configuring your application per environment, check out the configuration documentation.
Slack Driver
Alternatively, you may use the slack driver to send your messages where you may view them. This approach has the benefit of allowing you to actually inspect the final message.
Using a Global to Address
Finally, you may specify a global "to" address by invoking the alwaysTo method offered by the Sms
facade. Typically, this method should be called from the boot method of one of your application's service providers:
Events
We dispatch two events while sending sms messages. The SmsMessageSending
event is dispatched prior to a message being sent, while the SmsMessageSent
event is dispatched after a message has been sent. Remember, these events are dispatched when the sms is being sent, not when it is queued. You may create event listeners for these events within your application:
Custom Senders
You may wish to write your own senders to deliver sms via other services that this package does not support out of the box. To get started, define a class that extends the AlhajiAki\Sms\Senders\SenderInterface
class. Then, implement the send()
and __toString()
methods on your sender:
Once you've defined your custom sender, you may register it via the extend
method provided by the Sms
facade. Typically, this should be done within the boot method of your application's AppServiceProvider
service provider. A $config
argument will be passed to the closure provided to the extend
method. This argument will contain the configuration array defined for the sender in the application's config/sms.php
configuration file:
Once your custom sender has been defined and registered, you may create a sender definition within your application's config/sms.php
configuration file that utilizes the new sender:
TODOs
- [ ] Add SmsFake to help testing sms sending
- [ ] Write documentation for testing sms sending
- [ ] Write tests for the entire package
Testing
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-sms with dependencies
illuminate/contracts Version ^10.0|^11.0
illuminate/notifications Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0
propaganistas/laravel-phone Version ^5.3