PHP code example of ivfuture / laravel-event-notification

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

    

ivfuture / laravel-event-notification example snippets


// at the top of your class
use NotificationTrait;

//Controller's constructor
public function __construct()
{
    //subscribe to all the notification channels from database
    $this->subscribeToNotificationChannels();

    // ...

}

//sending a notification

$notification_channel = NotificationChannel::where('label', 'post-liked')->first();
if (!isset($notification_channel)) {
    return response()->json(['success' => false]);
}

$this->sendNotification($p_sender_id, $p_receiver_id, $p_notifiable_type, $p_notifiable_id, $notification_channel->id, $p_title, $p_description);


'providers' => [
    // ...
    Ivfuture\EventNotification\NotificationServiceProvider::class,
];

'redis' => [

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'redis'),
        //'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
    ],

   // ...
],

use NotificationTrait;

public function __construct()
{
    $this->subscribeToNotificationChannels();

    // ...

}


$notification_channel = NotificationChannel::where('label', 'post-liked')->first();

$this->sendNotification($p_sender_id, $p_receiver_id, $p_notifiable_type, $p_notifiable_id, $notification_channel->id, $p_title, $p_description);


Notification::latest()->where('receiver_id', auth()->user()->id )->get()->groupByDate();
config/app.php
bash
php artisan vendor:publish --provider="Ivfuture\EventNotification\NotificationServiceProvider"
bash
php artisan migrate
config/database.php