From bf63d4ac3b0e746b9e1d08533f596f6f1ed49d6c Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 30 Aug 2023 10:19:04 +0700 Subject: [PATCH] fix broadcast --- app/Http/Controllers/BroadcastController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/BroadcastController.php b/app/Http/Controllers/BroadcastController.php index 5bb223e..87eb02d 100644 --- a/app/Http/Controllers/BroadcastController.php +++ b/app/Http/Controllers/BroadcastController.php @@ -15,6 +15,12 @@ class BroadcastController extends Controller $data = $request->all(); $data['status_send'] = true; $data['created_by'] = $this->currentName; + if (isset($data['send_to_id'])) { + $idArray = $data['send_to_id']; + if (is_array($data['send_to_id'])) { + $data['send_to_id'] = implode(", ", $idArray); + } + } // dd($data); $result = Broadcast::create($data); if($result){ @@ -140,8 +146,10 @@ class BroadcastController extends Controller } break; - case 'user': - $user = User::where("id", $data['send_to_id'])->whereNotNull('fcm_token')->first(); + case 'users': + $idArray = explode(", ", $data['send_to_id']); + foreach ($idArray as $key => $value) { + $user = User::where("id", $value)->whereNotNull('fcm_token')->first(); if (isset($user)) { FCMService::send( $user->fcm_token, @@ -151,6 +159,7 @@ class BroadcastController extends Controller ] ); } + } break; default: