|
| 1 | +# Mobtexting notifications channel for Laravel 5.3+ |
| 2 | + |
| 3 | +This package makes it easy to send [Mobtexting notifications](https://mobtexting.com) with Laravel 5.3. |
| 4 | + |
| 5 | +## Contents |
| 6 | + |
| 7 | +- [Installation](#installation) |
| 8 | + - [Setting up your Mobtexting account](#setting-up-your-twilio-account) |
| 9 | +- [Usage](#usage) |
| 10 | + - [Available Message methods](#available-message-methods) |
| 11 | +- [Changelog](#changelog) |
| 12 | +- [Testing](#testing) |
| 13 | +- [Security](#security) |
| 14 | +- [Contributing](#contributing) |
| 15 | +- [Credits](#credits) |
| 16 | +- [License](#license) |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +You can install the package via composer: |
| 21 | + |
| 22 | +``` bash |
| 23 | +composer require mobtexting/laravel |
| 24 | +``` |
| 25 | + |
| 26 | +Add the service provider (only required on Laravel 5.4 or lower): |
| 27 | + |
| 28 | +```php |
| 29 | +// config/app.php |
| 30 | +'providers' => [ |
| 31 | + ... |
| 32 | + NotificationChannels\Mobtexting\MobtextingProvider::class, |
| 33 | +], |
| 34 | +``` |
| 35 | + |
| 36 | +### Setting up your Mobtexting account |
| 37 | + |
| 38 | +Add your Mobtexting Auth Token, and From Number (optional) to your `config/services.php`: |
| 39 | + |
| 40 | +```php |
| 41 | +// config/services.php |
| 42 | +... |
| 43 | +'mobtexting' => [ |
| 44 | + 'username' => env('MOBTEXTING_USERNAME'), // optional when using auth token |
| 45 | + 'password' => env('MOBTEXTING_PASSWORD'), // optional when using auth token |
| 46 | + 'token' => env('MOBTEXTING_AUTH_TOKEN'), // optional when using username and password |
| 47 | + 'from' => env('TWILIO_FROM'), // optional |
| 48 | +], |
| 49 | +... |
| 50 | +``` |
| 51 | + |
| 52 | +## Usage |
| 53 | + |
| 54 | +Now you can use the channel in your `via()` method inside the notification: |
| 55 | + |
| 56 | +``` php |
| 57 | +use NotificationChannels\Mobtexting\MobtextingChannel; |
| 58 | +use NotificationChannels\Mobtexting\MobtextingSmsMessage; |
| 59 | +use Illuminate\Notifications\Notification; |
| 60 | + |
| 61 | +class AccountApproved extends Notification |
| 62 | +{ |
| 63 | + public function via($notifiable) |
| 64 | + { |
| 65 | + return [MobtextingChannel::class]; |
| 66 | + } |
| 67 | + |
| 68 | + public function toMobtexting($notifiable) |
| 69 | + { |
| 70 | + return (new MobtextingSmsMessage()) |
| 71 | + ->text("Your {$notifiable->service} account was approved!"); |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +In order to let your Notification know which phone are you sending/calling to, the channel will look for the `phone_number` attribute of the Notifiable model. If you want to override this behaviour, add the `routeNotificationForMobtexting` method to your Notifiable model. |
| 77 | + |
| 78 | +```php |
| 79 | +public function routeNotificationForMobtexting() |
| 80 | +{ |
| 81 | + return '+1234567890'; |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +### Available Message methods |
| 86 | + |
| 87 | +#### MobtextingSmsMessage |
| 88 | + |
| 89 | +- `from('')`: Accepts a phone to use as the notification sender. |
| 90 | +- `text('')`: Accepts a string value for the notification body. |
| 91 | +- `to('')`: Accepts a string value for the notification to (over writes default). |
| 92 | + |
| 93 | +## Testing |
| 94 | + |
| 95 | +``` bash |
| 96 | +$ composer test |
| 97 | +``` |
| 98 | + |
| 99 | +## Security |
| 100 | + |
| 101 | +If you discover any security related issues, please email support@mobtexting.com instead of using the issue tracker. |
| 102 | + |
| 103 | +## Contributing |
| 104 | + |
| 105 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 106 | + |
| 107 | +## License |
| 108 | + |
| 109 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments