LaravelPackages.net
Acme Inc.
Toggle sidebar
mucts/laravel-sms

SMS SDK for Laravel 7

39
1
1.1.1
About mucts/laravel-sms

mucts/laravel-sms is a Laravel package for sms sdk for laravel 7. It currently has 1 GitHub stars and 39 downloads on Packagist (latest version 1.1.1). Install it with composer require mucts/laravel-sms. Discover more Laravel packages by mucts or browse all Laravel packages to compare alternatives.

Last updated

Laravel SMS

SMS for Laravel 7,based on mucts/sms

Latest Stable Version Total Downloads Latest Unstable Version License

Install

composer require mucts/laravel-sms

Usage

  • Created Notification
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use MuCTS\Laravel\SMS\Channels\Channel as SMSChannel;
use MuCTS\Laravel\SMS\Interfaces\Notification as SMSNotification;
use MuCTS\SMS\Interfaces\Message as MessageInterface;
use MuCTS\Laravel\SMS\Messages\Message;
class VerificationCode extends Notification implements SMSNotification
{
    use Queueable;

    public function via($notifiable)
    {
        return [SMSChannel::class];
    }

    public function toSMS($notifiable):MessageInterface
    {
        return (new Message())
            ->setContent('您的验证码为: 6379')
            ->setTemplate('SMS_001')
            ->setData(['code' => 6379]);
    }
}
  • Create user model
<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use MuCTS\SMS\Mobile;

class User extends Authenticatable
{
    use Notifiable;
 
    public function routeNotificationForSMS($notification)
    {
        return new Mobile($this->mobile, $this->area_code);
    }
}
  • Send SMS
<?php
// user Notifiable Trait
$user->notify(new VerificationCode());
// use Notification Facade
Notification::send($user, new VerificationCode());
// Send notifications to unregistered users or users with unbound mobile numbers.
Notification::route(
    SMSChannel::class,
    new Mobile(13333333333, 86)
)->notify(new VerificationCode());

Facade

<?php

use SMS;

SMS::send('13333333333','短信')

License

MIT

Star History Chart