尝试在laracast视频后创建用户注册/登录页面。
但是当我尝试注册用户时,它返回到同一页面而没有给出任何错误原因。我还注意到提供的信息没有存储在数据库中。
我很困惑,我不知道你做错了什么,你的帮助将会非常感激
以下是我的观点:
<div class="col-md-offset-1 col-md-8">
<h1 class="text-center ">Register</h1>
<form method="POST" action="register" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" email="email" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" required>
</div>
<div class="form-group">
<label for="password_confirmation">Password Confirmation</label>
<input type="password" class="form-control" name="password_confirmation" required>
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-reply"></i>Register</button>
</form>
</div>
这是我的控制器
public function create()
{
return view('registration.create');
}
public function store(Request $request)
{
//validate form
$this->validate(request(),[
'name' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed',
]);
//create and save user
$user = new User; //create new Post model object
$user->name = $request->name; //adding thing to the the Post object
$user->email = $request->email;
$user->password = $request->password;
//save user
$user->save(); //to save the new item into the DB
//$user = User::create(request(['name', 'email', 'password']));
//sign them in
auth()->login($user);
//redirect to the admin
return redirect('/admin');
}
虽然这是我的路线档案:
Route::get('register', 'RegistrationController@create');
Route::post('register', 'RegistrationController@store');
提前多多感谢
答案 0 :(得分:0)
检查您的表单,电子邮件字段中出现错误。它说:
应该是:
<input type="email" class="form-control" name="email" required>
所以,请替换电子邮件 =&#34;电子邮件&#34; 名称 =&#34;电子邮件&#34;
答案 1 :(得分:-1)
首先添加此错误块。所以,你很容易发现错误。
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
然后,你的错误在于形式行动。请将其替换为以下代码。
<form method="POST" action="{{ route('register') }}" enctype="multipart/form-data">