PHP code example of vance-page / laravel-notification-easysms

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

    

vance-page / laravel-notification-easysms example snippets


    'providers' => [
        // ...
        Vance\\LaravelNotificationEasySms\EasySmsChannelServiceProvider::class,
    ],
    

    

    namespace App\Notifications;

    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Notifications\Messages\MailMessage;
    use Vance\LaravelNotificationEasySms\Channels\EasySmsChannel;
    use Vance\LaravelNotificationEasySms\Messages\EasySmsMessage;

    class VerificationCode extends Notification
    {
        use Queueable;

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

        public function toEasySms($notifiable)
        {
            return (new EasySmsMessage)
                ->setContent('您的验证码为: 6379')
                ->setTemplate('SMS_001')
                ->setData(['code' => 6379]);
        }
    }
    

    
    
    namespace App;
    
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Overtrue\EasySms\PhoneNumber;
    
    class User extends Authenticatable
    {
        use Notifiable;
     
        public function routeNotificationForEasySms($notification)
        {
            return new PhoneNumber($this->number, $this->area_code);
        }
    }
    

    // 使用 Notifiable Trait
    $user->notify(new VerificationCode());
    // 使用 Notification Facade
    Notification::send($user, new VerificationCode());
    

    Notification::route(
        EasySmsChannel::class,
        new PhoneNumber(13333333333, 86)
    )->notify(new VerificationCode());
    
shell
    $ php artisan vendor:publish --provider="Vance\\LaravelNotificationEasySms\EasySmsChannelServiceProvider"