fixing user notification
This commit is contained in:
@@ -177,7 +177,6 @@ class ProfileController extends Controller
|
||||
'email_otp' => $emailotp,
|
||||
'mobile_otp' => $otp
|
||||
]);
|
||||
|
||||
} else if ($addUser && $user->email != $request->email) {
|
||||
//update
|
||||
$validator = validator::make($request->all(), [
|
||||
@@ -207,7 +206,6 @@ class ProfileController extends Controller
|
||||
);
|
||||
|
||||
return response()->json(['status' => 200, 'message' => 'Details Updated Successfully!', 'email_otp' => $emailotp]);
|
||||
|
||||
} else if ($addUser && $user->contact_number != $request->contact_number) {
|
||||
//mobile no,
|
||||
|
||||
@@ -230,7 +228,6 @@ class ProfileController extends Controller
|
||||
]
|
||||
);
|
||||
return response()->json(['status' => 200, 'message' => 'Details Updated Successfully!', 'mobile_otp' => $otp]);
|
||||
|
||||
}
|
||||
if ($addUser) {
|
||||
return response()->json(['status' => 200, 'message' => 'Details Updated Successfully!']);
|
||||
@@ -247,18 +244,18 @@ class ProfileController extends Controller
|
||||
|
||||
$userOtpData = UserOtpModel::where('user_id', $userId)->first();
|
||||
$userData = User::where('id', $userId)->first();
|
||||
|
||||
|
||||
if (!$userOtpData || !$userData) {
|
||||
return response()->json(['status' => 400, 'message' => 'User Data Not Found in database'], 400);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($isVerificationFor == 1) {
|
||||
|
||||
$emailOtp = $request->email_otp;
|
||||
$emailToUpdate = $request->email;
|
||||
|
||||
$userOtpData = UserOtpModel::where('user_id', $userId)->where('email_otp',$emailOtp)->first();
|
||||
$userOtpData = UserOtpModel::where('user_id', $userId)->where('email_otp', $emailOtp)->first();
|
||||
if (!$userOtpData) {
|
||||
return response()->json(['status' => 400, 'message' => 'OTP Did Not Matched!'], 400);
|
||||
}
|
||||
@@ -267,13 +264,13 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
$userData->email = $emailToUpdate;
|
||||
$userData->save();
|
||||
}
|
||||
$userData->save();
|
||||
}
|
||||
if ($isVerificationFor == 2) {
|
||||
$contactOtp = $request->contact_otp;
|
||||
$contactToUpdate = $request->contact_no;
|
||||
|
||||
$userOtpData = UserOtpModel::where('user_id', $userId)->where('contact_otp',$contactOtp)->first();
|
||||
$userOtpData = UserOtpModel::where('user_id', $userId)->where('contact_otp', $contactOtp)->first();
|
||||
if (!$userOtpData) {
|
||||
return response()->json(['status' => 400, 'message' => 'OTP Did Not Matched!'], 400);
|
||||
}
|
||||
@@ -282,12 +279,9 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
$userData->contact_number = $contactToUpdate;
|
||||
$userData->save();
|
||||
|
||||
|
||||
$userData->save();
|
||||
}
|
||||
return response()->json(['status' => 200, 'message' => 'Your OTP verified Successfully!']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['status' => 400, 'message' => 'Error Updating Details!'], 400);
|
||||
}
|
||||
@@ -295,14 +289,13 @@ class ProfileController extends Controller
|
||||
|
||||
public function resendOtpForProfileUpdate(Request $request)
|
||||
{
|
||||
try{
|
||||
try {
|
||||
$type = $request->type;
|
||||
$user_id = request()->user()->id;
|
||||
$credential = $request->credential;
|
||||
$otp = rand(1000,9999);
|
||||
$otp = rand(1000, 9999);
|
||||
// $getUser = User::find($user_id);
|
||||
if($type == 1)
|
||||
{
|
||||
if ($type == 1) {
|
||||
// type 1 for email otp
|
||||
// $email = $getUser->email;
|
||||
$mailData = [
|
||||
@@ -310,17 +303,15 @@ class ProfileController extends Controller
|
||||
'body' => 'This is for testing email using smtp.'
|
||||
];
|
||||
Mail::to($credential)->send(new OtpMail($mailData, $otp));
|
||||
UserOtpModel::where('user_id', $user_id)->update(['email_otp'=> $otp, 'expire_at'=>Carbon::now()->addMinutes(2)]);
|
||||
}
|
||||
else if($type == 2)
|
||||
{
|
||||
UserOtpModel::where('user_id', $user_id)->update(['email_otp' => $otp, 'expire_at' => Carbon::now()->addMinutes(2)]);
|
||||
} else if ($type == 2) {
|
||||
// $mobileNumber = $getUser->contact_number;
|
||||
$this->thirdPartyOTP($credential, $otp);
|
||||
UserOtpModel::where('user_id', $user_id)->update(['contact_otp'=> $otp,'expire_at'=>Carbon::now()->addMinutes(2)]);
|
||||
UserOtpModel::where('user_id', $user_id)->update(['contact_otp' => $otp, 'expire_at' => Carbon::now()->addMinutes(2)]);
|
||||
}
|
||||
return response()->json([
|
||||
'status'=>200,
|
||||
'message'=>'OTP has been send',
|
||||
'status' => 200,
|
||||
'message' => 'OTP has been send',
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 400);
|
||||
@@ -507,4 +498,36 @@ class ProfileController extends Controller
|
||||
}
|
||||
return response()->json(['status' => 201, 'message' => 'Please enter OTP']);
|
||||
}
|
||||
|
||||
public function readNotification(Request $request)
|
||||
{
|
||||
|
||||
$id = $request->id;
|
||||
// dd(Auth::guard('users')->user());
|
||||
// dd(getAllNotifications());
|
||||
if ($id) {
|
||||
Auth::guard('users')->user()->unreadNotifications->where('id', $id)->markAsRead();
|
||||
}
|
||||
$notifications = Auth::guard('users')->user()->notifications;
|
||||
// dd($notifications);
|
||||
$notificationHTML = '';
|
||||
$count = 0;
|
||||
foreach ($notifications as $data) {
|
||||
$count++;
|
||||
$read_at = $data->read_at ? 'style="color:#808080"' : 'style="color:black"';
|
||||
$oddEven = $count % 2 == 1 ? 'odd' : 'even';
|
||||
// $notificationHTML .= "<li class='item list-item ".$oddEven."' style='color:" . $read_at . ";'>
|
||||
$notificationHTML .= "<li class='item list-item ".$oddEven."' >
|
||||
<a class='read_notification' ".$read_at . "
|
||||
data-id='" . $data->id . "'>" . $data->data['message'] . "
|
||||
<p class='mb-0'>
|
||||
<strong>" . $data->created_at->diffForHumans() . "</strong>
|
||||
</p>
|
||||
</a>
|
||||
</li>";
|
||||
}
|
||||
if ($notificationHTML) {
|
||||
return response()->json(['status' => 200, 'data' => $notificationHTML, 'count'=>Auth::guard('users')->user()->unreadNotifications->count()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user