Laravel 中 RouteCollection 中的 NotFoundHttpException
NotFoundHttpException in RouteCollection in Laravel
首先,对于大多数人来说,如果我自己还没有做一些研究,我不会在这里问,我看到很多类似的标题问题,但它们似乎与我遇到的问题不同。
=实际开始=
所以我正在关注这个名为 Laravel 5.2 PHP 建立社交网络 的网络教程系列,我卡在了第三集的结尾。我的问题是,当我尝试单击 注册按钮 时,出现此错误:
1/1
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 755
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
我尝试修复 web.php
、welcome.blade.php
、UserController.php
任何人都可以帮助我了解问题所在吗?
web.php
<?php
/*
|--------------------------------------------------------------------------
| 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::get('/', function () {
return view('welcome');
});
Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
UserController.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){
$email = $request['email'];
$password = $request['password'];
}
}
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 Email</label>
<input type="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="first_name">Your First Name</label>
<input type="form-control" type="text" name="first_name" id="first_name">
</div>
<div class="form-group">
<label for="password">Your Password</label>
<input type="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 Email</label>
<input type="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="password">Your Password</label>
<input type="form-control" type="password" name="password" id="password">
</div>
<button type="submit" class="btn btn-primary"> Submit</button>
</form>
</div>
</div>
@endsection
当我 运行: php artisan route:list
+--------+----------+----------+--------+------------------------------------------------+----------
----+
| Domain | Method | URI | Name | Action | Middlewar
e |
+--------+----------+----------+--------+------------------------------------------------+----------
----+
| | GET|HEAD | / | | Closure | web
|
| | GET|HEAD | api/user | | Closure | api,auth:
api |
| | POST | signup | signup | App\Http\Controllers\UserController@postSignUp | web
|
+--------+----------+----------+--------+------------------------------------------------+----------
----+
编辑 2016 年 11 月 21 日 07:00 下午:值得注意的是,当我使用 Laravel 5.3 时,我不确定演示者使用的是什么,但他使用的是具有 routes.php 的项目,我只是尝试使用 web.php 来解决,因为它似乎是最接近的我需要遵循本教程的内容。我也有 link 作为 http://localhost/hiro/public/
看来路由本身没有问题
这对我来说真的只是一个猜测,但值得一试:
web.php
<?php
// Removed a forward slash from the route
Route::post('signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
welcome.blade.php
<div class="col-md-6">
<h3>Sign Up</h3>
<!-- Use a regular HTML route instead of Laravel's own -->
<form action="/signup" method="POST">
<div class="form-group">
<label for="email">Your Email</label>
<input type="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="first_name">Your First Name</label>
<input type="form-control" type="text" name="first_name" id="first_name">
</div>
<div class="form-group">
<label for="password">Your Password</label>
<input type="form-control" type="password" name="password" id="password">
</div>
<!-- Changed the submit button to input element instead of button -->
<input type="submit" class="btn btn-primary" value="Submit">
<input type="hidden" name="_token" value="{{Session::token()}}">
</form>
</div>
这是你的服务器配置。
请使用 /hiro/public
作为虚拟主机中的文档根目录。
或者将其添加到您的 .htaccess 文件中:
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
首先,对于大多数人来说,如果我自己还没有做一些研究,我不会在这里问,我看到很多类似的标题问题,但它们似乎与我遇到的问题不同。
=实际开始=
所以我正在关注这个名为 Laravel 5.2 PHP 建立社交网络 的网络教程系列,我卡在了第三集的结尾。我的问题是,当我尝试单击 注册按钮 时,出现此错误:
1/1
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 755
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
我尝试修复 web.php
、welcome.blade.php
、UserController.php
任何人都可以帮助我了解问题所在吗?
web.php
<?php
/*
|--------------------------------------------------------------------------
| 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::get('/', function () {
return view('welcome');
});
Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
UserController.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){
$email = $request['email'];
$password = $request['password'];
}
}
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 Email</label>
<input type="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="first_name">Your First Name</label>
<input type="form-control" type="text" name="first_name" id="first_name">
</div>
<div class="form-group">
<label for="password">Your Password</label>
<input type="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 Email</label>
<input type="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="password">Your Password</label>
<input type="form-control" type="password" name="password" id="password">
</div>
<button type="submit" class="btn btn-primary"> Submit</button>
</form>
</div>
</div>
@endsection
当我 运行: php artisan route:list
+--------+----------+----------+--------+------------------------------------------------+----------
----+
| Domain | Method | URI | Name | Action | Middlewar
e |
+--------+----------+----------+--------+------------------------------------------------+----------
----+
| | GET|HEAD | / | | Closure | web
|
| | GET|HEAD | api/user | | Closure | api,auth:
api |
| | POST | signup | signup | App\Http\Controllers\UserController@postSignUp | web
|
+--------+----------+----------+--------+------------------------------------------------+----------
----+
编辑 2016 年 11 月 21 日 07:00 下午:值得注意的是,当我使用 Laravel 5.3 时,我不确定演示者使用的是什么,但他使用的是具有 routes.php 的项目,我只是尝试使用 web.php 来解决,因为它似乎是最接近的我需要遵循本教程的内容。我也有 link 作为 http://localhost/hiro/public/
看来路由本身没有问题
这对我来说真的只是一个猜测,但值得一试:
web.php
<?php
// Removed a forward slash from the route
Route::post('signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
welcome.blade.php
<div class="col-md-6">
<h3>Sign Up</h3>
<!-- Use a regular HTML route instead of Laravel's own -->
<form action="/signup" method="POST">
<div class="form-group">
<label for="email">Your Email</label>
<input type="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="first_name">Your First Name</label>
<input type="form-control" type="text" name="first_name" id="first_name">
</div>
<div class="form-group">
<label for="password">Your Password</label>
<input type="form-control" type="password" name="password" id="password">
</div>
<!-- Changed the submit button to input element instead of button -->
<input type="submit" class="btn btn-primary" value="Submit">
<input type="hidden" name="_token" value="{{Session::token()}}">
</form>
</div>
这是你的服务器配置。
请使用 /hiro/public
作为虚拟主机中的文档根目录。
或者将其添加到您的 .htaccess 文件中:
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]