PHP code example of ghasedak / laravel-notification
1. Go to this page and download the library: Download ghasedak/laravel-notification 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/ */
namespace App\Http\Notifications;
use Ghasedak\LaravelNotification\GhasedakChannel;
use Ghasedak\LaravelNotification\GhasedakSimpleSms;
use Illuminate\Notifications\Notification;
class SendSms extends Notification
{
public function via($notifiable)
{
return [GhasedakChannel::class];
}
public function toSms($notifiable)
{
// send simple message
return (new GhasedakSimpleSms)->message('Hello, World!')->linenumber('300xxxxx');
}
}
public function routeNotificationForSms()
{
return $this->phone;
}
use Ghasedak\LaravelNotification\GhasedakSimpleSms;
$user->notify(new GhasedakSimpleSms());
// App\Http\Notifications\SendSimpleNotification.php
namespace App\Http\Notifications;
use Ghasedak\LaravelNotification\GhasedakChannel;
use Ghasedak\LaravelNotification\GhasedakSimpleSms;
use Illuminate\Notifications\Notification;
class SendSimpleNotification extends Notification
{
public function __construct($params)
{
$this->params = $params;
}
public function via($notifiable)
{
return [GhasedakChannel::class];
}
public function toSms($notifiable)
{
return (new GhasedakSimpleSms)
->message($this->params['message'])
->linenumber($this->params['linenumber'])
->senddate($this->params['senddate'] ?? null)
->checkid($this->params['checkid'] ?? null);
}
}
$arr = array(
'message' => 'Hello, World!', // message
'linenumber' => '3000xxxxx', // choose a line number from your account
);
$user->notify(new GhasedakSimpleSms($arr));
// App\Http\Notifications\SendOTPNotification.php
namespace App\Http\Notifications;
use Ghasedak\LaravelNotification\GhasedakChannel;
use Ghasedak\LaravelNotification\GhasedakOTPSms;
use Illuminate\Notifications\Notification;
class SendOTPNotification extends Notification
{
public function __construct($params)
{
$this->params = $params;
}
public function via($notifiable)
{
return [GhasedakChannel::class];
}
public function toSms($notifiable)
{
return (new GhasedakOTPSms)
->type($this->params['type'])
->template($this->params['template'])
->params($this->params['params']);
}
}
$params = ['param1', 'param2', 'param3'];
$arr = array(
'type' => 1, // 1 for text message and 2 for voice message
'template' => 'my-template', // name of the template which you've created in you account
'params' => $params, // parameters (supporting up to 10 parameters)
);
$user->notify(new SendSimpleNotification($arr));