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/ */

    

ghasedak / laravel-notification example snippets


composer 

// config/services.php

'ghasedak' => [
    'api_key' => env("GHASEDAK_API_KEY"),
    'linenumber' => env('LINE_NUMBER', null),
]

GHASEDAK_API_KEY=your_api_key
LINE_NUMBER=your_line_number

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));

$params = ['1', '2'];
$arr = array(
    'type' => 1,
    'template' => 'template',
    'params' => $params
);
$user->notify(new SendOTPNotification($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));
shell script
php artisan make:notification SendSimpleNotification