我是Laravel的新手,所以我开始学习Laracast的课程,然后那个上课的人去了用户的认证并猜到等 . 寄存器工作正常,它进入带有散列密码的数据库,它使用户保持刚注册登录(并且可以完成登录用户在网站上应该做的所有事情) . 当我转到我的登录表单并尝试登录时,它不会重定向并给出错误 . 即使用户/密码凭据不正确,它也会重新加载 .
需要注册它如何将用户保存到数据库中 .
$user = User::create([
'name' => request('name'),
'email' => request('email'),
'password' => bcrypt(request('password'))
]);
login form...
<form method="POST" action="/login">
{{ csrf_field() }}
<div class="form-group">
<label for="Email">Email:</label>
<input type="email" class="form-control" id="Email" name="Email" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
@include ('layouts.errors')
</form>
web.php for routing
Route::get('/', 'PostsController@index')->name('home');
Route::get('/posts/create', 'PostsController@create');
Route::post('/posts', 'PostsController@store');
Route::get('/posts/{post}', 'PostsController@show');
Route::post('/posts/{post}/comments', 'CommentsController@store');
Route::get('/register', 'RegistrationController@create');
Route::post('/register', 'RegistrationController@store');
Route::get('/login', 'SessionsController@create')->name('login');
Route::post('/login', 'SessionsController@store');
Route::get('/logout', 'SessionsController@destroy');
The controller that handles the login
<?php
class SessionsController extends Controller
{
public function __construct()
{
$this->middleware('guest');
}
public function create()
{
return view('sessions.create');
}
public function store()
{
// Attempt to authenticate the user.
if (!auth()->attempt(request(['email', 'password']))) {
return back();
}
// Redirect them to the homepage
return redirect()->home();
}
public function destroy()
{
auth()->logout();
return redirect()->home();
}
}
Errors.php
<div class="form-group">
<div class="alert alert-errors">
<ul>
@foreach($errors->all() as $error)
<li> {{ $error }} </li>
@endforeach
</ul>
</div>
</div>
1 回答
看看你的表格 . 输入的名称是控制器访问它们所需的名称 .
在您声明的电子邮件和密码的表单中 .
在Controller中,您尝试访问电子邮件和密码 .
这可能是登录失败的原因,您刚刚被重定向到Page,因为执行的代码是
所以将表单更改为
如果这是有效的,请告诉我 .