Edit File: NewOrderNotify.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 Auth; use App\Notifications\NotifyUser as Notify ; class NewOrderNotify 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) { $settings = Setting::all()->pluck('value', 'key'); $user = Auth::user(); $order = $order; $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_en' => 'you have a new near order', 'type' => 'new_order', 'order_id' => $order->id, 'order_type' => $order->type, 'order_status' => 'open', ]; $this->users = $users; } /** * Execute the job. * * @return void */ public function handle() { $tokens = []; $users=$this->users; if ($users) { foreach ($users as $user) { if (isset($user->devices)) { if ($user->devices->count() > 0) { foreach ($user->devices as $device) { if($device->user->new_orders_notify=='true') { $tokens[] = $device->device_id; } } } } $this->sendNotification($tokens, $this->data); $user->notify(new Notify($this->data)); } } } }
Back to File Manager