Edit File: UserFinishOrder.php
<?php namespace App\Jobs; use App\Traits\Firebase; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use App\Notifications\NotifyUser as Notify ; class UserFinishOrder implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Firebase; /** * Create a new job instance. * * @return void */ protected $users, $data, $order; public function __construct($users, $order , $delegate,$type='delegate') { $user = $delegate; $order = $order; $title_ar =' قام ' .$user->name. ' بانهاء الطلب ' ; $title_en = $user->name.'finished the order' ; $message_ar = ' قام '. $user->name . ' بانهاء الطلب '; $message_en =$user->name.'finished the order'; $sender_avatar=$user->AvatarPath; $this->data = [ 'sender' => $user->id, 'sender_name' => $user->name, 'sender_avatar' =>$sender_avatar , 'title_ar' =>$title_ar , 'title_en' => $title_en , 'message_ar' => $message_ar, 'message_en' =>$message_en, 'type' =>'user_finished_order' , 'order_id' =>$order->id, 'order_type' =>$order->type, 'order_status' =>$order->statusForUser(), ]; $this->users = $users; } /** * Execute the job. * * @return void */ public function handle() { $androidTokens = []; $iosTokens = []; $webTokens = []; $user = $this->users; if (isset($user->devices)) { if ($user->devices->count() > 0) { foreach ($user->devices()->where('device_type' , 'ios')->get() as $device) { $iosTokens[] = $device->device_id; } foreach ($user->devices()->where('device_type' , 'android')->get() as $device) { $androidTokens[] = $device->device_id; } foreach ($user->devices()->where('device_type' , 'web')->get() as $device) { if($device->user->new_orders_notify=='true'){ $webTokens[] = $device->device_id; } } $user->notify(new Notify($this->data)); $this->sendNotification($iosTokens, $androidTokens ,$webTokens, $this->data); } } } }
Back to File Manager