我对 laravel 很陌生,我正在做用户注册和登录,但我收到一个错误



此路由不支持POST方法。支持的方法:GET、HEAD。我对laravel很陌生我正在进行用户注册和登录但是我得到了一个错误

这是给出错误的控制器


namespace AppHttpControllers;
use IlluminateHttpfacade;
use Request;
use DB;
class hotsmoke extends Controller
{
function login() {
return view('hot_smoke_login');
}
function signup() {
return view('sign-Up');
}
function login2() {
return view('dashboard');
}
function store() {
$uname= Request::input('name');
$uemail = Request::input('email');
$unumber= Request::input('number');
$uaddress= Request::input('address');
$upass= Request::input('password');


DB::unprepared("insert into customers (name, email,number,address,password) values ('$uname','$uemail','$unumber','$uaddress','$upass')");
return redirect('/hot_smoke_login');
}
function match2() {
$uemail = Request::input('email');
$upass = Request::input('password');

$loginData = DB::select('select password from users where email = ?', [$uemail]);

if (count($loginData) > 0){

foreach ($loginData as $tablepass) {

if (($tablepass->password) == $upass){
return view('dashboard');
}
else{
$error='Password does not match';
return view('hot_smoke_login')->with('error',$error);
}
}
}
}

}

没有运行的刀片视图

<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/login.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hotsmoke</title>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 p-0" style=" height: 100vh; overflow: hidden;">
<img src="images/hero-img.jpg" alt="" width="100%">
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 p-5">
<a href="javascript: history.go(-1)"><i class="fa-solid fa-arrow-left backBtn"></i></a>
<div class="align-items-center justify-content-center d-flex flex-column">
<h3 class="text-white">Login to <strong style="color: #ce913a;">HotSmoke</strong></h3>
<p class="mb-4 secondary-color">We know the cuisines and your taste better than anyone!</p>
<form method="post" id="login">
<div class="form-group first d-flex flex-column">
<label class="primary-color" for="username">Email</label>
<input type="text" class="email" id="username">
</div>
<div class="form-group last mb-3 d-flex flex-column">
<label class="primary-color" for="password">Password</label>
<input type="password" class="email" id="password">
</div>
<div class="d-flex mb-1 align-items-center">
<label class="control control--checkbox mb-0"><span class="caption">Remember me</span>
<input type="checkbox" checked="checked" />
<div class="control__indicator"></div>
</label>
<span class="ml-auto"><a href="forget-password.html" class="forgot-pass" style="color: #e0ae66">Forgot
Password</a></span>
</div>
<a href="sign-Up.html" class="secondary-color">Do not have an Account?</a>
<small class="text-danger " id="error" style="display: none;"></small>
<br><br>
<button class="email-button">Log In</button>
</form>
</div>
</div>
</div>
</div>

<script src="js/bootstrap.min.js"></script>
<script src="https://kit.fontawesome.com/5e8b9def84.js" crossorigin="anonymous"></script>
<script src="js/login.js"></script>
</body>
</html>

和我的路由

Route::get('sign-Up', [hotsmoke::class, 'signup']);
Route::post('sign-Up', [hotsmoke::class, 'store']);
Route::get('hot_smoke_login', [hotsmoke::class, 'login']);
Route::get('hot_smoke_login', [hotsmoke::class, 'match2']);

请指路

我希望这将工作。在每一个输入字段中添加name属性,并提及您想要调用它的名称。

例如<input type="text" class="email" name="username">,对每个输入都这样做,在表单标签之后使用@csrf像这样的令牌,路由名应该是动作

<form action="/sign-Up" method="post" id="login">
@csrf
...
</form>

我认为你需要做的第一件事是为你的表单元素添加一个'action'属性,它指向你想要提交表单的端点在本例中,它的格式是

action="{{ url('/sign-Up') }}"

最新更新