https://github.com/moceanapi/laravel-notification-channel
Mocean as notification channel for Laravel
https://github.com/moceanapi/laravel-notification-channel
Last synced: 10 months ago
JSON representation
Mocean as notification channel for Laravel
- Host: GitHub
- URL: https://github.com/moceanapi/laravel-notification-channel
- Owner: MoceanAPI
- License: mit
- Created: 2019-07-03T02:30:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T20:06:09.000Z (over 4 years ago)
- Last Synced: 2025-02-08T17:09:42.266Z (11 months ago)
- Language: PHP
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mocean Laravel Notification
===========================
[](https://packagist.org/packages/mocean/laravel-notification-channel)
[](https://travis-ci.com/MoceanAPI/laravel-notification-channel)
[](https://github.styleci.io/repos/194965639)
[](https://packagist.org/packages/mocean/laravel-notification-channel)
[](https://packagist.org/packages/mocean/laravel-notification-channel)
## Installation
To install the library, run this command in terminal:
```bash
composer require mocean/laravel-notification-channel
```
### Laravel 5.5
You don't have to do anything else, this package autoloads the Service Provider and create the Alias, using the new Auto-Discovery feature.
### Laravel 5.4 and below
Add the Service Provider and Facade alias to your `config/app.php`
```php
'providers' => [
Mocean\Notification\MoceanChannelServiceProvider::class,
]
```
## Usage
You must publish the config file as this will use [Laravel Mocean](https://github.com/MoceanAPI/laravel-mocean) as a package.
```bash
php artisan vendor:publish --provider="Mocean\Laravel\MoceanServiceProvider"
```
Create a notification class, refer [laravel official docs](https://laravel.com/docs/notifications#creating-notifications)
```php
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class InvoicePaid extends Notification
{
use Queueable;
public function via($notifiable)
{
//define mocean-sms as notification channel
return ['mocean-sms'];
}
public function toMoceanSms($notifiable)
{
//return the text message u want to send here
return 'You have received an invoice';
//you can also return an array for custom options, refer moceanapi docs
return [
'mocean-text' => 'You have received an invoice',
'mocean-dlr-url' => 'http://test.com'
];
}
}
```
to specify which attribute should be used to be a notifiable entity, create method `routeNotificationForMoceanSms`
```php
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForMoceanSms($notification)
{
//make sure user model has this attribute, else the notification will not be sent
return $this->phone;
}
}
```
send the notification to a user
```php
$user->notify(new InvoicePaid());
```
you can also send the notification to a custom phone number without using user model
```php
use Notification;
Notification:route('mocean-sms', '60123456789')
->notify(new InvoicePaid());
```
## License
Mocean Laravel Notification is licensed under the [MIT License](LICENSE)