嘿,伙计们,我是新来的laravel,我正试图建立一个大学项目。在注册部分,我无法验证用户的密码和电子邮件。如果凭据是正确的,它会重定向我到上一页,就像我想要的。但如果凭据是错误的,那么它不会重定向我到主页,但该页只是重新加载。
验证职能:
public function user_register(Request $request){
$res = false;
$request->validate([
"name"=>"required",
"email"=>"required|email|unique:custom__auths",
"password"=>"required|min:5|max:12"
]);
$user = new Custom_Auth();
$user->name=$request->name;
$user->email=$request->email;
$user->pasword=$request->password;
$res = $user->save();
echo $res;
if($res==1){
return back()->with('success','you have registered successfully');
}
else{
return redirect('/');
}
}
数据库中表:
public function up()
{
Schema::create('custom__auths', function (Blueprint $table) {
$table->id();
$table->string("name");
$table->string("email")->unique();
$table->string("password");
$table->timestamps();
});
}
注册视图:
@extends('Layouts.Master')
@section('content')
<link rel="stylesheet" href="{{asset('/Assets/CSS/Auth.css')}}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div class="container">
<input type="checkbox" id="flip">
<div class="cover">
<div class="front">
<img class="backImg" src="https://cdn.pixabay.com/photo/2018/01/31/07/36/sunset-3120484_960_720.jpg" alt="">
<div class="text">
<span class="text-1">Helping you grow<br> stronger each day</span>
<span class="text-2">Let's code together</span>
</div>
</div>
<div class="back">
<img class="backImg" src="https://cdn.pixabay.com/photo/2018/01/31/07/36/sunset-3120484_960_720.jpg" alt="">
<div class="text">
<span class="text-1">Complete miles of journey <br> with one step</span>
<span class="text-2">Let's get started</span>
</div>
</div>
</div>
<div class="forms">
<div class="form-content">
<div class="signup-form" >
<div class="title">Signup</div>
<form action="{{route('UserAuth')}}" method="post">
@csrf
<div class="input-boxes">
<div class="input-box">
<i class="fas fa-user"></i>
<input name="name" type="text" placeholder="Enter your name" required>
</div>
<div class="input-box">
<i class="fas fa-envelope"></i>
<input name="email" type="email" placeholder="Enter your email" required>
</div>
<div class="input-box">
<i class="fas fa-lock"></i>
<input name="password" type="password" placeholder="Enter your password" required>
</div>
<div class="button input-box">
<input type="submit" value="Sumbit">
</div>
<div class="text sign-up-text">Already have an account?<a href="/login" style="color: blue"> Login now</a></div>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection
我试着用dd来了解问题的根本原因,但不幸的是我无法找到问题的根本原因。任何帮助将不胜感激!!
1条答案
按热度按时间uxhixvfz1#
我认为“页面重载”意味着验证失败,但您没有显示错误消息。
根据Laravel文档,如果
$request->validate()
失败会发生什么:如果在传统HTTP请求过程中验证失败,则将生成指向上一个URL的重定向响应。
所以它会自动重定向回来,正如你所说的-“页面重新加载”。
我假设您只是没有显示验证错误。
同样,从相同的文档中,示例如何显示它们:
$errors
变量将从进程中自动填充。