Edit File: Notify.php
<?php namespace App\Jobs; use App\Traits\Firebase; use Illuminate\Bus\Queueable; use App\Notifications\NotifyUser ; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Support\Facades\Notification; class Notify implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Firebase; /** * Create a new job instance. * * @return void */ protected $users , $data, $auth, $req; public function __construct($users , $request = [], $user = []) { $this->auth = $user; $this->data = [ 'sender' => $user->id, 'sender_name' => $user->name, 'sender_avatar' => $user->avatar, 'title_ar' => $request['title_ar'] , 'title_en' => $request['title_en'] , 'message_ar' => $request['message_ar'], 'message_en' => $request['message_en'], 'type' => 'admin_notify' , ]; $this->users = $users; $this->req = $request; } /** * Execute the job. * * @return void */ public function handle() { // $tokens = []; // foreach ($this->users as $user) { // foreach ($user->devices as $device) { // if($device->user->new_orders_notify=='true') { // $tokens[] = $device->device_id; // } // } // } // // $this->sendNotification($tokens , $this->data) ; // Notification::send($this->users, new NotifyUser($this->data)); $androidTokens = []; $iosTokens = []; $webTokens = []; $user = $this->users; if ($user->new_orders_notify == 'true') { 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) { $webTokens[] = $device->device_id; } $user->notify(new Notify($this->data)); $this->sendNotification($iosTokens, $androidTokens, $webTokens, $this->data); } } } } }
Back to File Manager