When I apply validation rules in my code they give me this error I tried a lot to solve it but never get a solution. Below is my Password Controller
public function otpSend(Request $request)
{
$otp = rand(10000, 99999);
$std = Student::where('email', '=', $request->email)->first();
$rules = Validator::make($request->all(), [
'email' => 'required|email',
]);
$email = Mail::to($std->email)->send(new MailVerifyOtp($otp));
if ($rules->fails()) {
return response([
"code" => 400,
"message" => "Email Not Exist",
]);
} else {
return response([
"code" => 200,
"message" => "OTP send Successfully",
"otp" => $otp,
]);
}
}
When I enter an empty or wrong email address the showing me that error. Below is the attachment showing the error.
