samedi 2 septembre 2017

Delay in Laravel Push Notifications

everyone I am developing a project and I am using real time notifications using pusher and event broadcasting. What I need is, When I am sending same notification to multiple users then I want to add 5 seconds delay on each iteration of the loop. I am sharing source code with you please have a look and guide me how can I do it. I have tried this code but it creates only one notification and then showing some error. I mean to say it when the loop starts sending notifications to all the owners(users) then only first iteration works then showing this error.

When a user clicks on place order this function will check unique owners from cart table and start sending the notifications about the order.

function placeOrder(Request $request){     
      // return $request->usrToken;
       $customer = User::find($request->customerId);
       $menu_items = null;
        $owners = Cart::where('token', '=', $request->usrToken)->get()->unique('owner_id');
        $itr = count($owners);
        foreach ($owners as $key => $owner) {
          $menu_items = Cart::where('owner_id' , '=' , $owner->owner_id)->where('token', '=', $request->usrToken)->get();
          $no_of_items = count($menu_items);
          $restaurant = Owner::find($owner->owner_id)->restaurant;
          $transaction = $this->create_transaction($customer , $restaurant , $no_of_items);
          $target = Owner::find($owner->owner_id);              
          $target->notify(new NewOrderArrived($customer , $menu_items , $request->address, $transaction->id))->delay(5);                  
        }
       $customer->orderLastTimeOrNot = 1;
       $customer->save();            
       session()->flash('update_message' , 'Your meal will be delivered soon, dont forget to give rating after enjoying meal :)');
       session()->flash('ordered_last_time' , 'Your meal will be delivered soon, dont forget to give rating after enjoying meal :)');
       Cart::where('token', '=', $request->usrToken)->update(['token' => $request->usrToken.'processing']);
       return back();
    }

The error occurring is:

"Calling delay function on null" 

like this....

Any information you need more would be provided. Please guide me I need to complete this project.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire