created notification count api and modified get notification api

This commit is contained in:
Ritikesh yadav
2024-06-18 12:37:16 +05:30
parent b10afb7235
commit 88cc443878
4 changed files with 15 additions and 6 deletions

View File

@@ -229,11 +229,19 @@ class HomeController extends Controller
return response()->json(['status' => 200, 'message' => 'All Notifications mark as read']);
}
public function getUserNotificationCountApi(Request $request)
{
$user = User::find($request->user()->id);
$count = $user->unreadNotifications->count();
return response()->json(['status'=>200,'count'=>$count]);
}
public function getAllNotificationsApi(Request $request)
{
$user = User::find($request->user()->id);
$user->notifications->markAsRead();
$dataArray = array();
foreach ($user->unreadNotifications as $data) {
foreach ($user->notifications as $data) {
$notify['id'] = $data->id;
$notify['message'] = $data->data['message'];
$notify['time'] = $data->created_at->diffForHumans();