Skip to content
Snippets Groups Projects
Commit 25a48b79 authored by W's avatar W
Browse files

fixing fcm

parent b6119db4
No related merge requests found
......@@ -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);
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment