输出应在/login上显示令牌。但我一点击登录按钮,就会被引导到一个空白页面。
也有类似的问题被问到,但我还是没能解决。请有人帮我。
UserController.php
<?php
namespace AppHttpControllers;
use IlluminateSupportFacadesHash;
use IlluminateHttpRequest;
use AppModelsUser;
class UserController extends Controller
{
function login(Request $req)
{
return $req->input;
}
}
web.php
<?php
use IlluminateSupportFacadesRoute;
use AppHttpControllersUserController;
Route::get('/login', function () {
return view('login');
});
Route::post("/login",[UserController::class,'login']);
姓名、电子邮件和密码记录在数据库中可见。
型号-用户.php
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
登录页面
<form action="login" method="POST">
<div class="mb-3">
@csrf
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" name="password" class="form-control" id="exampleInputPassword1">
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
检查表单标记中的action
属性。
用/login
代替login
似乎是正确的。