Akshay Deshmukh
Akshay Deshmukh

Reputation: 1292

Delay laravel push notification for 5 second

I am using ""davibennun/laravel-push-notification": "dev-laravel5" " for sending push notification. What i want is delay in sending notification after hit but dont want to stop the process. Is there any idea how can i do this or is this possible?

Following is the code to send push notification:

     $pushNotification = PushNotification::app('appNameAndroid')->to($token);
     $pushNotification->adapter->setAdapterParameters(['sslverifypeer' => false]);
     $pushNotification->send($message);

Thanks in advance.

Upvotes: 2

Views: 1620

Answers (1)

Akshay Deshmukh
Akshay Deshmukh

Reputation: 1292

I found how to do this. Following are the steps.

  1. Run the following command

    php artisan queue:table
    php artisan migrate

  2. Change .env

    QUEUE_DRIVER=database

  3. Create a job

    php artisan make:job JobName

//In Job file

  1. I have mentioned 2 protected variable in my job file

    $message,$deviceToken

  2. In _construct i assigned a value to the above variables.

    public function __construct($deviceToken, $message)

    {
        $this->deviceToken = $deviceToken;
        $this->message = $message;
    }
    
  3. In handle method

    $pushNotification = PushNotification::app('appNameAndroid')->to($this->deviceToken); $pushNotification->adapter->setAdapterParameters(['sslverifypeer' => false]); $pushNotification->send($this->message);

//In my controller

$job = (new JobName($deviceToken, $message))->delay(10);

$this->dispatch($job);

Upvotes: 3

Related Questions