PHP code example of zsardarov / laravel-msg

1. Go to this page and download the library: Download zsardarov/laravel-msg 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/ */

    

zsardarov / laravel-msg example snippets


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
            }
        }
    }
}


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

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;
    }
}

$user->notify(new SmsNotification('Sample'));
bash
php artisan vendor:publish --provider="Zsardarov\Msg\MsgServiceProvider"
bash
php artisan make:notification SmsNotification