首先,對於大多數情況下,我不會在這裏問我是否還沒有做過一些調查,我看到很多類似的問題,但它們看起來並不是我的問題。Laravel的RouteCollection中的NotFoundHttpException
=實際開始=
所以我下面這個網絡教程系列稱爲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' => '[email protected]',
'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工匠路線:列表
+--------+----------+----------+--------+------------------------------------------------+----------
----+
| 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\[email protected] | web
|
+--------+----------+----------+--------+------------------------------------------------+----------
----+
編輯2016年11月21日07:00下午:應該是值得一提的是,雖然我使用Laravel 5.3,我不知道什麼是演示使用,但他使用的項目有routes.php,我只是試圖通過使用web.php解決,因爲它似乎是最接近我需要按照教程。我也有鏈接作爲http://localhost/hiro/public/
可以運行'PHP工匠路線:list'請 – James
這可能是你想要的東西: | POST |註冊|註冊| App \ Http \ Controllers \ UserController @ postSignUp |網 –
,因爲你在GET方法中訪問該路由,但在你的代碼路由中,你只允許方法POST'Route :: post('/註冊','允許在該URL中的其他方法'Route :: match(' GET','POST','PUT'等等)' – Beginner