1. Go to this page and download the library: Download prgayman/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/ */
use Prgayman\Sms\Drivers\Driver;
use Prgayman\Sms\SmsDriverResponse;
use Prgayman\Sms\Contracts\DriverMultipleContactsInterface;
class CustomDriver extends Driver implements DriverMultipleContactsInterface {
# You not need to run events or store history
# package automatically run all events and store history
public function send() : SmsDriverResponse
{
$request = [
"to" => $this->getTo(),
'from' => $this->getFrom(),
'body' => $this->getMessage(),
];
try {
# Handler send message
$response = null;
return new SmsDriverResponse($request, $response, true);
} catch (\Exception $e) {
return new SmsDriverResponse($request, null, false, $e->getMessage());
}
}
}
"drivers"=>[
.......
# Use custom driver
'your-driver-name'=>[
'handler'=> \App\SmsDrivers\CustomDriver::class
],
# Use supported drivers but different name
# Copy driver object and change name
"new-log-driver" => [
"driver" => "log",
'channel' => env('SMS_LOG_CHANNEL'),
],
]
# Use driver
Sms::driver("your-driver-name")
->to($to)
->from($from)
->message($message)
->send();
# Or set custom driver in default driver or set
# SMS_DRIVER=your-driver-name in dotenv file
Sms::setDefaultDriver("your-driver-name");
Sms::to($to)
->from($from)
->message($message)
->send();
use Illuminate\Notifications\Notification;
use Prgayman\Sms\SmsNotification;
class SendSmsNotification extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['sms']; # add this channel
}
/**
* @param mixed $notifiable
* @return \Prgayman\Sms\SmsNotification
*/
public function toSms($notifiable)
{
# Send message with default driver
return (new SmsNotification)
->to("+962790000000")
->from("SenderName")
->message("Test New Message");
# Send message with select driver
return (new SmsNotification)
->driver('array')
->to("+962790000000")
->from("SenderName")
->message("Test New Message");
}
}
use Prgayman\Sms\Facades\SmsHistory;
# Get all
$histories = SmsHistory::get();
# Use Filters all filter is optional
$histories = SmsHistory::recipients("+962790000000")
->senders(["SendName"])
->statuses([
Prgayman\Sms\Models\SmsHistory::SUCCESSED,
Prgayman\Sms\Models\SmsHistory::FAILED,
])
->drivers(["log","array"])
->driverNames(["custom_name"])
->get();
# Or can use helper function
$histories = smsHistory()
->recipients("+962790000000")
->senders(["SendName"])
->statuses([
Prgayman\Sms\Models\SmsHistory::SUCCESSED,
Prgayman\Sms\Models\SmsHistory::FAILED,
])
->drivers(["log","array"])
->driverNames(["custom_name"])
->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.