LaravelPackages.net
Acme Inc.
Toggle sidebar
zsardarov/laravel-msg

MSG.ge integration for Laravel

6
0
v1.0.0
About zsardarov/laravel-msg

zsardarov/laravel-msg is a Laravel package for msg.ge integration for laravel. It currently has 0 GitHub stars and 6 downloads on Packagist (latest version v1.0.0). Install it with composer require zsardarov/laravel-msg. Discover more Laravel packages by zsardarov or browse all Laravel packages to compare alternatives.

Last updated

MSG.ge integration for Laravel

The package for sending SMS messages using MSG.ge API.

Installation

composer require zsardarov/laravel-msg

You can publish config using:

php artisan vendor:publish --provider="Zsardarov\Msg\MsgServiceProvider"

Update the .env file

MSG_ALTERNATIVE_PASSWORD is optional.

MSG_SERVICE_ID=1
MSG_CLIENT_ID=1
MSG_PASSWORD=password
MSG_USERNAME=user
MSG_ALTERNATIVE_PASSWORD=

Usage

use Zsardarov\Msg\MsgService;
use Zsardarov\Msg\Enums\GatewayStatus;
use Zsardarov\Msg\Enums\DeliveryStatus;

class SampleController extends Controller
{
    public function sms(MsgService $sender)
    {        
        $result = $sender->send('9955XXXXXXXX', 'Text');
        
        if ($result->getStatusCode() === GatewayStatus::ACCEPTED) {
            // now we can check status
            $status = $sender->status($result->getMessageId());
            
            if ($status === DeliveryStatus::PENDING || $status === DeliveryStatus::SENT) {
                // message has been sent
            }
        }
    }
}

Notifications

To use it with Laravel notifications, you firstly must add toMsg() method in User model:


class User extends Authenticatable
{
    use Notifiable; 
    
    public function toMsg()
    {
        return $this->mobile;
    }
}

Create notification:

php artisan make:notification SmsNotification
use Illuminate\Notifications\Notification;
use Zsardarov\Msg\Channels\MsgChannel;

class SmsNotification extends Notification
{
    private $message;
    
    public function __construct(string $message) 
    {
        $this->message = $message;
    }
    
    public function via($notifiable)
    {
        return [MsgChannel::class];
    }
    
    public function toSms()
    {
        return $this->message;
    }
}

Then send notification to user:

$user->notify(new SmsNotification('Sample'));
Comments