PHP code example of arhinful / laravel-mnotify

1. Go to this page and download the library: Download arhinful/laravel-mnotify 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/ */

    

arhinful / laravel-mnotify example snippets


use Arhinful\LaravelMnotify\MNotify;



namespace App\Http\Controllers;

use Arhinful\LaravelMnotify\MNotify;
use Illuminate\Http\Request;

class UserNotificationController extends Controller
{
    public function sendQuickReminder(){
        $notify = new MNotify();
        // list of receivers, can be array (multiple receivers) or string (single receiver)
        $receivers = ['0542092800', '0507455860']; // or $receivers = '0507455860';
        // message to send, must be string
        $message = "Hello users, a quick reminder, we have a scheduled meeting at 2:00 PM today.";
        $notify->sendQuickSMS($receivers, $message);
    }
}


$notify = new MNotify();
$receivers = ['0542092800', '0507455860'];
$message_template_id = 1;
$notify->sendQuickSMSFromTemplate($receivers, $message_template_id);


namespace App\Notifications;

use Arhinful\LaravelMnotify\NotificationDriver\MNotifyMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class TestNotification extends Notification
{
    use Queueable;

    public function via($notifiable)
    {
        return [MNotifyChannel::class];
    }

    public function toMNotify($notifiable)
    {
        return (new MNotifyMessage())->message("Hello User: $notifiable->name");
    }
}


use Illuminate\Database\Eloquent\Model;

class EmailController extends Model
{

    // optional, but mobile number must exist among user's attributes if this method doesn't exist
    public function routeNotificationForMNotify() : string{
        return '0257906340';
    }
}



namespace App\Http\Controllers\EmailController;
use App\Models\User;
use App\Notifications\TestNotification;

class EmailController extends controller
{

    public function notifyUserAction()
    {
        $user = \App\Models\User::first();
        $user->notify(new TestNotification());
        return "Message Sent";
    }
}