https://github.com/zingimmick/laravel-sms
Provides sms notification channel for Laravel.
https://github.com/zingimmick/laravel-sms
laravel notification sms
Last synced: 5 months ago
JSON representation
Provides sms notification channel for Laravel.
- Host: GitHub
- URL: https://github.com/zingimmick/laravel-sms
- Owner: zingimmick
- License: mit
- Created: 2020-04-10T06:21:55.000Z (over 6 years ago)
- Default Branch: 6.x
- Last Pushed: 2026-02-06T03:08:03.000Z (6 months ago)
- Last Synced: 2026-02-06T12:46:09.465Z (6 months ago)
- Topics: laravel, notification, sms
- Language: PHP
- Homepage:
- Size: 532 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Sms
[](https://github.com/zingimmick/laravel-sms/actions/workflows/tests.yml)
[](https://codecov.io/gh/zingimmick/laravel-sms)
[](https://packagist.org/packages/zing/laravel-sms)
[](https://packagist.org/packages/zing/laravel-sms)
[](https://packagist.org/packages/zing/laravel-sms)
[](https://packagist.org/packages/zing/laravel-sms)
[](https://scrutinizer-ci.com/g/zingimmick/laravel-sms)
[](https://github.styleci.io/repos/254559831)
[](https://codeclimate.com/github/zingimmick/laravel-sms/maintainability)
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fzingimmick%2Flaravel-sms?ref=badge_shield)
Laravel Sms is used to notify via sms and send a message.
## Thanks
Many thanks to:
* [JetBrains](https://www.jetbrains.com/?from=LaravelSms) for the excellent
**PhpStorm IDE** and providing me with an open source license to speed up the
project development.
[](https://www.jetbrains.com/?from=LaravelSms)
## Requirements
- [PHP 8.0+](https://php.net/releases/)
- [Composer](https://getcomposer.org)
- [Laravel 8.0+](https://laravel.com/docs/releases)
## Installation
### Composer
Execute the following command to get the latest version of the package:
```terminal
composer require zing/laravel-sms
```
### Laravel
Publish Configuration
```shell
php artisan vendor:publish --provider "Zing\LaravelSms\SmsServiceProvider"
```
### Add Connections
This package based on [overtrue/easy-sms](https://github.com/overtrue/easy-sms), driver is the gateway.
## Usage
### Channel
#### Create a Notification
```php
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
class Verification extends Notification implements ShouldQueue
{
use Queueable;
protected $code;
/**
* Verification constructor.
*
* @param $code
*/
public function __construct($code)
{
$this->code = $code;
}
public function via()
{
return ['sms'];
}
public function toSms($notifiable)
{
return "验证码 {$this->code},您正在进行身份验证,打死也不要告诉别人哦!";
}
}
```
#### Add notification route for sms to your notifiable
```php
use Illuminate\Notifications\Notifiable;
class User
{
use Notifiable;
public function routeNotificationForSms($notification)
{
return $this->phone;
}
}
```
#### Send notification
```php
use Illuminate\Support\Facades\Notification;
$user = new User();
// use Notifiable Trait
$user->notify(new Verification('1111'));
// use Notification Facade
Notification::send($user, new Verification('1111'));
```
#### Send to anonymous notifiable
```php
use Illuminate\Support\Facades\Notification;
use Zing\LaravelSms\SmsNumber;
use Zing\LaravelSms\Channels\SmsChannel;
// use channel class name
Notification::route(SmsChannel::class, new SmsNumber(18188888888, 86))->notify(new Verification('1111'));
// use channel alias
Notification::route('sms', new SmsNumber(18188888888, 86))->notify(new Verification('1111'));
```
### Facade
#### Send Message
```php
use Zing\LaravelSms\Facades\Sms;
// use default connection
Sms::send(18188888888, 'test message.');
// use specific connection
Sms::connection('null')->send(18188888888, 'test message.');
// or
Sms::via('null')->send(18188888888, 'test message.');
```
## Specific usage
### Use specific connection for notification
**NOTE:** Only support for `Zing\LaravelSms\SmsMessage`
```php
use Zing\LaravelSms\SmsMessage;
public function toSms($notifiable)
{
return (new SmsMessage())->onConnection('log');
}
```
### Make PhoneNumber notifiable
**NOTE:** Only support for `Zing\LaravelSms\SmsNumber`
```php
use Zing\LaravelSms\SmsNumber;
(new SmsNumber(18188888888))->notify(new Verification('1111'));
```
## License
Laravel Sms is open-sourced software licensed under the [MIT license](LICENSE).
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fzingimmick%2Flaravel-sms?ref=badge_large)