我有这样的表格:
<form action="{{route('login')}}" id="loginForm" method="POST">
<div class="text-center" style="font-size: 30px; font-family: 'Poppins', sans-serif;">Login</div><br />
<div class="input-group">
<span class="input-group-label"><i class="fa fa-envelope"></i></span>
<input class="input-group-field" id="lemail" name="lemail" placeholder="Insert your email" type="email" required>
</div>
<p class="help-text" id="email">Type in your email and password to log in.</p>
<div class="input-group">
<span class="input-group-label"><i class="fa fa-lock"></i></span>
<input class="input-group-field" id="lpassword" name="lpassword" placeholder="Type in your password" type="password" required>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<br />
<div class="align-center">
<button type="submit" class="button secondary align-center" href="#">Login</button>
</div>
</form>
如您所见,我有action="{{route('login')}}"
因为我想使用该路线:
Route::post('/', [
'as' => 'login',
'uses' => 'LoginUser@login'
]);
这就是功能:
public function login(Request $request)
{
$this->validate($request, [
'lemail' => 'required|string|email|max:255',
'lpassword' => 'required|string|min:6|max:128',
]);
$email = $request->input('lemail');
$password = $request->input('lpassword');
if (Auth::attempt(['email' => $email, 'password' => $password])) {
// Authentication passed...
return redirect()->intended('/home')
->with('flash_notice', 'You are successfully logged in.');
}
return redirect()->intended('/')
->with('flash_error', 'Your username/password combination was incorrect.');
}
问题是,在填写字段并发送表单后,它告诉我电子邮件和密码字段为空,但它们不是。
我这样做是因为我在页脚中有它,我希望它可以在所有页面上工作,但我无法让它工作。
答案 0 :(得分:0)
将您的路线用作:
Route::post('/', 'LoginUser@login')->name('login');
答案 1 :(得分:0)
在路线中提供姓名
Route::post('/', [
'as' => 'login',
'uses' => 'LoginUser@login'
])->name('login');
而且我认为您忘记了表单或令牌中的 {{csrf_field()}} :)
答案 2 :(得分:0)