va/smart-sms is a Laravel package for a package to send sms notification in laravel apps..
It currently has 6 GitHub stars and 120 downloads on Packagist (latest version v1.0.2).
Install it with composer require va/smart-sms.
Discover more Laravel packages by va
or browse all Laravel packages to compare alternatives.
Last updated
Sms Notification service and channel for send sms with smartsms.ir
composer require va/smart-sms
php artisan vendor:publish --tag=smart-sms
'line_number' => env('SMS_LINE_NUMBER'),
'user_id' => env('SMS_USER_ID'),
'password' => env('SMS_PASSWORD'),
'default_sms_rcpt' => env('SMS_DEFAULT_SMS_RCPT'),
'mobile_field_name' => env('SMS_MOBILE_FIELD_NAME', 'mobile')
SMS_LINE_NUMBER=10001010
SMS_USER_ID=12345
SMS_PASSWORD=123456789
SMS_DEFAULT_SMS_RCPT=0901***1020 // You're phone number for test on local mode or (.env => APP_ENV=local)
SMS_MOBILE_FIELD_NAME=mobile // Name of the mobile field in you're User model or users migration or users table
// The default message:
$message = 'You're message;
// If we want to send a message to $user:
$user->notify(SmsNotificationFacade::message($message)); // mobile = $user->mobile, message = $message
or
$request->user->notify(SmsNotificationFacade::message($message)); // mobile = $user->mobile, message = $message
// If we want to send a mesage to another mobile number:
$user->notify(SmsNotificationFacade::message($message)->mobile('0901***1020')); // mobile = 0901***1020, message = $message
// If we want to send a message to another mobile numbers (Send Group message):
$user->notify(SmsNotificationFacade::message($message)->group(['0901***1020', '0901***3040']));
Make a new notification
php artisan make:sms-notification SendActivationNotification
In which directory was this class made?
app/Notifications/Message/SendActivationNotification.php
Content of this Notification
<?php
namespace App\Notifications\Message;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Va\SmartSms\Channels\SmartSmsChannel;
class SendActivationNotification extends Notification
{
use Queueable;
public $message;
public $mobile;
public $group;
/**
* SendActivationNotification constructor.
* @param string|null $message
* @param string|null $mobile
* @param array $group
*/
public function __construct(string $message = null, string $mobile = null, array $group = [])
{
$this->message = $message;
$this->mobile = $mobile;
$this->group = $group;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [SmartSmsChannel::class];
}
public function toChannel()
{
return [
'text' => "You're message" OR $this->message, // You're default (text of message)
'mobile' => $this->mobile,
'group' => $this->group
];
}
}
Use this Notification for send message
// If we want to send a message with this notification
$user->notify(new SendActivationNotification()); // mobile = $user->mobile, message = (Default meassge in notification)
// If we want to send a message to another mobile number:
$user->notify(new SendActivationNotification(null, '0901***1020')); // mobile = $user->mobile, message = (Default meassge in notification)
// If we want to send a message to another mobile numbers (Send Group message):
$user->notify(new SendActivationNotification(null, null, ['0901***1020', '0901***3040'])); // mobile = array, message = (Default meassge in notification)
// If we want to push a message to notification class
$message = "You're message";
$user->notify(new SendActivationNotification($message)); // mobile = $user->mobile, message = $message