diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 8ca3e91651fb5fa869350d1336c8a0f540a1fdd3..4109396b2df7623b2d62a5ed02ed4d53d8b1ebf3 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -34,40 +34,50 @@ class CommentController extends Controller $request->validate([ 'comment' => 'required', ]); + $task = Tasks::where([ + 'id' => $taskId + ])->first(); + if (is_null($task)) { + return response(json_encode([ + 'data' => NULL, + 'statusMessage' => 'error' + ]), 404); + } else { - $comment = Comment::create([ - 'comment' => $request->comment, - 'task_id' => $taskId, - 'user_id' => $userId - ]); - //FireBaseeeee - $serviceAccount = ServiceAccount::fromArray(Config::get('constants.GOOGLE_FIREBASE_SERVICE')); - $firebase = (new Factory) - ->withServiceAccount($serviceAccount) - ->create(); - - $messaging = $firebase->getMessaging(); - - $notification = Notification::fromArray([ - 'title' => 'Dapet comment nih', - 'body' => $request->comment - ]); - - $data = [ - 'task_id' => $taskId, - 'task_id' => $taskId - ]; - - $message = CloudMessage::withTarget('topic', 'whe') - ->withNotification($notification) - ->withData($data); // optional; - - $messaging->send($message); + $comment = Comment::create([ + 'comment' => $request->comment, + 'task_id' => $taskId, + 'user_id' => $userId + ]); + //FireBaseeeee + $serviceAccount = ServiceAccount::fromArray(Config::get('constants.GOOGLE_FIREBASE_SERVICE')); + $firebase = (new Factory) + ->withServiceAccount($serviceAccount) + ->create(); + + $messaging = $firebase->getMessaging(); + + $notification = Notification::fromArray([ + 'title' => 'Dapet comment nih', + 'body' => $request->comment + ]); + + $data = [ + 'task_id' => $taskId, + 'user_id' => $userId + ]; + $groupId = (string) $task->group_id; + $message = CloudMessage::withTarget('topic', $groupId) + ->withNotification($notification) + ->withData($data); // optional; + + $messaging->send($message); - ////////////// - return response(json_encode([ - 'data' => NULL, - 'statusMessage' => 'success' - ]), 200); + ////////////// + return response(json_encode([ + 'data' => NULL, + 'statusMessage' => 'success' + ]), 200); + } } }