VerifyController.php
verifyUser
verifyUserpublic function verifyUser(Request $request)
{
// Extract the verification code from the request
$verificationCode = $request->input('verificationCode');
// Search for a user with the provided verification code in the UserAccount model
$user = UserAccount::where('verification_code', $verificationCode)->first();
// Check if a user with the given verification code is found
if (isset($user)) {
// If found, set the 'verified' attribute to true and save the user
$user->verified = true;
$user->save();
// Prepare a success response
$response = [
'SUCCESS' => 1,
];
// Return the success response
return $response;
} else {
// If no user is found with the given verification code, prepare a failure response
$response = [
'SUCCESS' => 0,
];
// Return the failure response
return $response;
}
}To explain what this verifyUser method does:
Receive Request Parameter:
The function takes a
Requestobject as a parameter, representing an HTTP request.It extracts the 'verificationCode' from the request using
$request->input('verificationCode').
Search for User with Verification Code:
It then uses the Laravel Eloquent ORM to search for a user in the
UserAccountmodel where the 'verification_code' matches the extracted verification code.The result of the query is stored in the
$uservariable.
Check if User Found:
It checks if a user with the given verification code is found by using
isset($user).
Update User Verification Status:
If a user is found, it sets the 'verified' attribute of the user to true using
$user->verified = true.It then saves the changes to the user model with
$user->save().
Prepare Success Response:
If a user is found and successfully verified, it prepares a success response array with
'SUCCESS' => 1.
Prepare Failure Response:
If no user is found with the given verification code, it prepares a failure response array with
'SUCCESS' => 0.
Return Response:
Finally, it returns the prepared response (either success or failure) as a JSON response to the client making the request.
Last updated