2016-11-21 133 views
0

首先,對於大多數情況下,我不會在這裏問我是否還沒有做過一些調查,我看到很多類似的問題,但它們看起來並不是我的問題。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.phpwelcome.blade.phpUserController.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/

+0

可以運行'PHP工匠路線:list'請 – James

+0

這可能是你想要的東西: | POST |註冊|註冊| App \ Http \ Controllers \ UserController @ postSignUp |網 –

+0

,因爲你在GET方法中訪問該路由,但在你的代碼路由中,你只允許方法POST'Route :: post('/註冊','允許在該URL中的其他方法'Route :: match(' GET','POST','PUT'等等)' – Beginner

回答

0

這是你的服務器配置。

請在您的虛擬主機中使用/hiro/public作爲您的文檔根目錄。

或者添加到您的。htaccess文件:

RewriteEngine On 
RewriteRule ^(.*)$ public/$1 [L] 
+0

你的意思是像創建一個新的Apache虛擬主機? –

+0

不一定。只需編輯現有的虛擬主機的'DocumentRoot'。或者,如前所述,您可以編輯.htaccess文件。目標是擺脫URL中的/ public。 – sleepless

+0

是的,這是爲我做的,我幾乎要詛咒自己,把我的頭撞在我的桌子,屏幕和筆記本電腦上。 我創建了一個名爲hiro的虛擬主機,並通過http:// hiro/ 訪問該應用程序。這已修復,謝謝所有試圖幫助我的人。 –

0

似乎沒有什麼錯誤的路線本身。

這其實只是我的一個猜測,但值得給予一拍:

web.php

<?php 

// Removed a forward slash from the route 
Route::post('signup', [ 
    'uses' => '[email protected]', 
    '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> 
+0

不同的錯誤。 找不到對象! 在此服務器上找不到請求的URL。推薦頁面上的鏈接似乎是錯誤或過時的。請通知該頁面的作者關於錯誤。 如果您認爲這是服務器錯誤,請與網站管理員聯繫。 –

+0

不錯,儘管。 –

+0

如果您嘗試將路由更改爲'GET'以用於測試目的並嘗試返回某些內容,會發生什麼情況? F.e:'Route :: get('/ signup',function(){「返回」Hello World!「; });'。它是否會返回「Hello World!」? –

相關問題