Laravel 每当我尝试提交我创建的注册表单时,都会弹出错误“404 not found”
Laravel error "404 not found" pops up anytime I try to submit a signup form that I created
我已经进入 laravel 几天了,我正在接受教程指导。我被引导创建一个注册和登录表格。问题是,每当我在填写注册表单后单击提交按钮时,都会收到“404,未找到”错误。我还在命令行上 运行 "php artisan route:list" 并且我的注册路径列在那里。最糟糕的是我不知道错误来自哪里。
代码如下:
WEB.PHP
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route :: group (['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
});
?>
WELCOME.BLADE.PHP
@extends('layouts.master')
@section ('title')
welcome!
@endsection
@section ('content')
<div class = "row">
<div class = "col-md-6">
<h3> Sign Up </h3>
<form action ="{{route ('signup')}}" method = "post">
<div class = "form-group">
<label for= "email"> your E-mail </label>
<input class = "form-control" type="text" name = "email" id= "email">
</div>
<div class = "form-group">
<label for= "first_name"> your first name </label>
<input class = "form-control" type="text" name = "first_name" id= "first_name">
</div>
<div class = "form-group">
<label for= "password"> your password </label>
<input class = "form-control" type="password" name = "password" id= "password">
</div>
<button type = "submit" class = "btn btn-primary">submit</button>
<input type = "hidden" name = "_token" value="{{Session::token() }}">
</form>
</div>
<div class = "col-md-6">
<h3> Sign In </h3>
<form action = "#" method = "post">
<div class = "form-group">
<label for= "email"> your E-mail </label>
<input class = "form-control" type="text" name = "email" id= "email">
</div>
<div class = "form-group">
<label for= "password"> your password </label>
<input class = "form-control" type="password" name = "password" id= "password">
</div>
<button type = "submit" class = "btn btn-primary">submit</button>
</form>
</div>
@endsection
伙计们,这是 UserController 文件
用户CONTROLLER.PHP
<?php
namespace App\Http\Controllers;
use App\user;
use Illuminate\Http\Request;
class UserController extends Controller {
public function postSignUp(Request $request){
$email = $request ['email'];
$first_name = $request ['first_name'];
$password = bcrypt($request ['password']);
$user = new user();
$user -> email = $email;
$user -> first_name = first_name;
$user -> password = $password;
$user -> save();
return redirect() -> back();
}
public function postSignIn (Request $request){
}
}
?>
如果您尝试手动构建 url 并在浏览器中输入 /signup 会发生什么情况?如果你得到 404 尽管你在浏览器中硬输入 url 那么你在 web.php 中有问题另一个条目可能是
有几种情况可能会导致这种情况:
- 该路线不存在 - 不太可能,因为您已检查过
route:list
- 您重定向到的路由不存在 - 从
POST
请求到控制器的典型响应是 redirect()
到视图或路由。这可能是您的错误发生的地方。
- 您有两条或更多条路线对应 URL - 由于路线文件中路线从上到下的评估顺序,这可能是偶然发生的。
伙计们,我解决了。我使用命令提示符输入代码“php artisan serve --port= xxxx”,xxxx 是我连接 laravel 的新端口的编号,然后我能够在单击我创建的表单的注册按钮。我看到错误在哪里。所以我在 UserController.php 代码中忘记了一个美元符号。感谢你们的努力。
我已经进入 laravel 几天了,我正在接受教程指导。我被引导创建一个注册和登录表格。问题是,每当我在填写注册表单后单击提交按钮时,都会收到“404,未找到”错误。我还在命令行上 运行 "php artisan route:list" 并且我的注册路径列在那里。最糟糕的是我不知道错误来自哪里。
代码如下:
WEB.PHP
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route :: group (['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
});
?>
WELCOME.BLADE.PHP
@extends('layouts.master')
@section ('title')
welcome!
@endsection
@section ('content')
<div class = "row">
<div class = "col-md-6">
<h3> Sign Up </h3>
<form action ="{{route ('signup')}}" method = "post">
<div class = "form-group">
<label for= "email"> your E-mail </label>
<input class = "form-control" type="text" name = "email" id= "email">
</div>
<div class = "form-group">
<label for= "first_name"> your first name </label>
<input class = "form-control" type="text" name = "first_name" id= "first_name">
</div>
<div class = "form-group">
<label for= "password"> your password </label>
<input class = "form-control" type="password" name = "password" id= "password">
</div>
<button type = "submit" class = "btn btn-primary">submit</button>
<input type = "hidden" name = "_token" value="{{Session::token() }}">
</form>
</div>
<div class = "col-md-6">
<h3> Sign In </h3>
<form action = "#" method = "post">
<div class = "form-group">
<label for= "email"> your E-mail </label>
<input class = "form-control" type="text" name = "email" id= "email">
</div>
<div class = "form-group">
<label for= "password"> your password </label>
<input class = "form-control" type="password" name = "password" id= "password">
</div>
<button type = "submit" class = "btn btn-primary">submit</button>
</form>
</div>
@endsection
伙计们,这是 UserController 文件
用户CONTROLLER.PHP
<?php
namespace App\Http\Controllers;
use App\user;
use Illuminate\Http\Request;
class UserController extends Controller {
public function postSignUp(Request $request){
$email = $request ['email'];
$first_name = $request ['first_name'];
$password = bcrypt($request ['password']);
$user = new user();
$user -> email = $email;
$user -> first_name = first_name;
$user -> password = $password;
$user -> save();
return redirect() -> back();
}
public function postSignIn (Request $request){
}
}
?>
如果您尝试手动构建 url 并在浏览器中输入 /signup 会发生什么情况?如果你得到 404 尽管你在浏览器中硬输入 url 那么你在 web.php 中有问题另一个条目可能是
有几种情况可能会导致这种情况:
- 该路线不存在 - 不太可能,因为您已检查过
route:list
- 您重定向到的路由不存在 - 从
POST
请求到控制器的典型响应是redirect()
到视图或路由。这可能是您的错误发生的地方。 - 您有两条或更多条路线对应 URL - 由于路线文件中路线从上到下的评估顺序,这可能是偶然发生的。
伙计们,我解决了。我使用命令提示符输入代码“php artisan serve --port= xxxx”,xxxx 是我连接 laravel 的新端口的编号,然后我能够在单击我创建的表单的注册按钮。我看到错误在哪里。所以我在 UserController.php 代码中忘记了一个美元符号。感谢你们的努力。