我一直在尝试将我的一个旧项目迁移到 Laravel,通过 Laravel Breeze 处理身份验证。
在一个文件中,我有两张用于登录和注册的帖子表格。 登录的是我无法工作的:
<div class="login">
<span>Welcome Back!</span>
<h2 class="title">
Sign In
</h2>
<form action="{{ route('login') }}" method="POST" id="loginform">
@csrf
<div>
<input type="text" class="username" placeholder="Username" name="login_username" id="login_username">
</div>
<div>
<input type="password" class="password" placeholder="Password" name="login_password" id="login_password">
</div>
<div>
<button class="btn" name="Login_Button">Login</button>
</div>
</form>
<p class="existing-account" onclick="move('toRegister')">Not yet registered?</p>
</div>
路线设置如下:
Route::get('login', [AuthenticatedSessionController::class, 'create'])
->name('login');
Route::post('login', [AuthenticatedSessionController::class, 'store']);
最后在 AuthenticatedSessionController 中我得到了这个:
public function store(LoginRequest $request): RedirectResponse
{
dd($request);
$request->authenticate();
$request->session()->regenerate();
return redirect(route('home'));
}
但由于某种原因,我没有得到数据转储,也没有得到重定向。我停留在表格所在的同一页面上。老实说,我不知道从哪里开始,因为路线似乎是正确的。
在这种情况下你应该经常检查
在我们目前的情况下
return redirect(route('home'));
需要使用
Helper
。确保您可能遇到的所有语法错误都已解决,并且您使用的所有资源的命名空间也在其使用的代码位置使用。
您很可能只是遇到一个错误,您可以在服务器日志中检查该错误,其中包含一条消息,告诉您错误是什么以及错误发生位置的堆栈跟踪。