Edit File: OrderIntransitNotify.php
<?php namespace App\Jobs; use App\Models\Setting; 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 OrderIntransitNotify implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Firebase; /** * Create a new job instance. * * @return void */ protected $users, $data, $order, $status; public function __construct($users, $order, $status) { $settings = Setting::all()->pluck('value', 'key'); $user = auth('api')->user(); $order = $order; $status = $status; $message_ar = ''; $message_en = ''; if ($status == "reached_receive_location") { $message_ar = 'تم الوصول لموقع الاستلام' . ' (' . $order->id . ') '; $message_en = 'delegate is delivered to receive location' . ' (' . $order->id . ') '; } else { $message_ar = 'تم الوصول لموقع التسليم' . ' (' . $order->id . ') '; $message_en = 'delegate is delivered to deliver location' . ' (' . $order->id . ') '; } $this->data = [ 'sender' => $user->id, 'sender_name' => $user->name, 'sender_avatar' => $user->AvatarPath, 'title_ar' => $settings['site_name'], 'title_en' => $settings['site_name'], 'message_ar' => $message_ar, 'message_en' => $message_en, 'type' => 'order_intransit', 'order_id' => $order->id, 'order_type' => $order->type, 'order_status' => $order->statusForUser(), 'order_owner' => $order->user?->id, ]; $this->users = $users; } /** * Execute the job. * * @return void */ public function handle() { $ios_tokens = []; $android_tokens = []; $user = $this->users; if (isset($user->devices)) { if ($user->devices->count() > 0) { foreach ($user->devices()->where('device_type', 'ios')->get() as $device) { if ($user->new_orders_notify == 'true') { $ios_tokens[] = $device->device_id; } } foreach ($user->devices()->where('device_type', 'android')->get() as $device) { if ($user->new_orders_notify == 'true') { $android_tokens[] = $device->device_id; } } $user->notify(new Notify($this->data)); $this->sendNotification($ios_tokens, $android_tokens, $this->data , $user->lang , $user->notify_sound); } } } }
Back to File Manager