Edit File: NotificationController.php
<?php namespace App\Http\Controllers\Admin; use App\Jobs\Notify; use App\Jobs\NotifyUser; use App\Models\User; use App\Jobs\SendSms; use App\Models\Admin; use App\Jobs\AdminNotify; use App\Jobs\SendEmailJob; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class NotificationController extends Controller { public function index(Type $var = null) { return view('admin.notifications.index'); } public function sendNotifications(Request $request) { if ($request->user_type == 'all_users' ) { $rows = User::where('type' , 'user')->with(['devices'])->get() ; // }else if($request->user_type == 'active_users'){ // $rows = User::where('type' , 'user')->where('active' , true)->get() ; // }else if($request->user_type == 'not_active_users'){ // $rows = User::where('type' , 'user')->where('active' , false)->get() ; // }else if($request->user_type == 'blocked_users'){ // $rows = User::where('type' , 'user')->where('block' , true)->get() ; // }else if($request->user_type == 'not_blocked_users'){ // $rows = User::where('type' , 'user')->where('block' , false)->get() ; }else if($request->user_type == 'admins'){ $rows = Admin::get() ; // }else if($request->user_type == 'delegates'){ // $rows = User::where('type' , 'delegate')->where('approve' , 'accept')->get() ; }else if($request->user_type == 'stores'){ $rows = User::where('type' , 'store')->whereHas('store')->where('approve' , 'accept')->get() ; } if ($request->type == 'notify') { if ($request->user_type == 'admins') { dispatch(new AdminNotify($rows, $request)); }else if ($request->user_type == 'all_types' ) { $rows = Admin::get() ; dispatch(new AdminNotify($rows, $request)); $rows = User::with(['devices'])->get() ; dispatch(new NotifyUser($rows, $request , $request->type , 'all')); }else{ dispatch(new NotifyUser($rows, $request , $request->type , 'all')); } }else if ($request->type == 'email') { $rows = User::with(['devices'])->whereNotNull('email')->pluck('email')->toArray() ; dispatch(new SendEmailJob($rows, $request)); }else{ dispatch(new SendSms($rows->pluck('phone')->toArray() , $request->message)); } return response()->json() ; } }
Back to File Manager