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() { $users = $this->users; if ($users) { foreach ($users as $user) { $ios_tokens = []; $android_tokens = []; if (isset($user->devices)) { if ($user->devices->count() > 0) { foreach ($user->devices()->where('device_type', 'ios')->get() as $device) { if ($device->user->new_orders_notify == 'true') { $ios_tokens[] = $device->device_id; } } foreach ($user->devices()->where('device_type', 'android')->get() as $device) { if ($device->user->new_orders_notify == 'true') { $android_tokens[] = $device->device_id; } } // $user->notify(new Notify($this->data, $this->req, $this->auth)); $this->sendNotification($android_tokens, $this->data, 'android'); $this->sendNotification($ios_tokens, $this->data, 'ios'); } } } } // dd($this->users); Notification::send($this->users, new NotifyUser($this->data)); } }
Back to File Manager