PHP code example of karunais13 / multiple-notification-provider

1. Go to this page and download the library: Download karunais13/multiple-notification-provider 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/ */

    

karunais13 / multiple-notification-provider example snippets


	...
	
	'providers' => array(
		...
		Karu\NpNotification\NpNotificationProvider::class,
	],
	
	...

        'aliases' => [
            ...
            NotificationHelper: Karu\NpNotification\Facade\NotificationFacade::class
        ]




return [
    /*
     * The 3rd party service use to send notification .
     * Supported for now : web -> onesignal  email -> default (Will add in more service in feature)
     */
    'service' => [
        'web'    => 'onesignal',
        'email'  => 'default',
        'mobile' => 'onesignal'
    ],

    /*
     * Array contain template for all the notification.
     */
    'template' => [
        /*
         * Unique template code for notification helper to choose form the view folder.
         */
        '{templateCode}' => [
            'web_push'  => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ],
            'mobile_push' => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ],
            'email' => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ],
            'sms'   => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ]
        ]
    ],

    /*
     * Method used to get user information.
     * This method must be added to respective modal class
     */
    'user_info_method' => 'getNotificationUserInfo',

    /*
     * Table names
     */
    'tables' => [
        'notification_store' => 'notification',
        'notification_token' => 'notification_token',
    ],

    /*
     * User Type
     */
    'user_type' => [
        'd' => \App\Models\Sample::class, // Sample
        'c' => \App\Models\Sample2::class, // Sample
    ],


    /*
     * Store/Log Notification on database
     */
    'log_notification' => true
];
    


/*
|--------------------------------------------------------------------------
| Notification
|--------------------------------------------------------------------------
|
*/
Route::group(['prefix'=> 'notification'], function(){
    /*
    |
    | User Class -> set in the notification config with type as key
    |
    */
    Route::put('token/{user_class}/{user_id}', 'NotificationTokenController@update')
        ->name('noti.update-installation');
    Route::put('/{notification_id}', 'NotificationController@update')
        ->name('noti.update');
});


 //Default Setting
 $notiSetting = [
    'email' => true,
    'notification' => true, //Web & Mobile
    'sms' => false
 ];

 $noti = NotificationHelper::setConfig($notiSetting)->sendNotificationToUser($user, $templateCode, $extraParam);


 $noti = NotificationHelper::sendNotificationToUser($user, $templateCode, $extraParam);

    /**
     * @param $userId
     * @param $userType (User class name)
     * @param $notiType (NOTIFICATION_TYPE_EMAIL | NOTIFICATION_TYPE_WEB_PUSH | NOTIFICATION_TYPE_NATIVE_PUSH | NOTIFICATION_TYPE_SMS)
     * @param  int  $pastDay (For all record send 0) 
     *
     * @return collection
     */
 $notiList = NotificationHelper::getUnReadUserNotificationList($userId, $userType, $notiType, $pastDay);

    /**
     * @param $userId
     * @param $userClassType (from notification config user type) 
     * @param $token
     *
     * @return bool
     */
 $notiList = NotificationHelper::unsubscribeUser($userId, $userClassType, $token);

 php artisan vendor:publish --provider=Karu\NpNotification\NpNotificationProvider