PHP code example of mocean / laravel-notification-channel
1. Go to this page and download the library: Download mocean/laravel-notification-channel 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/ */
mocean / laravel-notification-channel example snippets
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'
];
}
}
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;
}
}
$user->notify(new InvoicePaid());
use Notification;
Notification:route('mocean-sms', '60123456789')
->notify(new InvoicePaid());