2016-07-01 60 views
0

與laravel 5.1laravel 5.1路線錯誤信息

工作每當我去mywebsite.com/home我重定向到auth/login路徑,但它加載此錯誤消息。林不知道是什麼原因造成這個問題,一切都仍然是開箱即用。林不知道什麼即時通訊俯瞰

MethodNotAllowedHttpException in RouteCollection.php line 219:

這裏是我的routes.php文件

<?php 

/* 
|-------------------------------------------------------------------------- 
| Application Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register all of the routes for an application. 
| It's a breeze. Simply tell Laravel the URIs it should respond to 
| and give it the controller to call when that URI is requested. 
| 
*/ 

Route::get('/', function() { 
    return view('welcome'); 
}); 

// Authentication routes 
Route::get('login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 
Route::get('auth/logout', 'Auth\[email protected]'); 

// Registration routes 
Route::get('register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 
Route::controllers(['password' => 'Auth\PasswordController',]); 

Route::get('/home', '[email protected]'); 

// Using A Route Closure 
Route::get('profile', ['middleware' => 'auth', function() { 
    // Only authenticated users may enter... 
    Route::auth(); 
}]); 

這裏是我的HomeController.php文件

<?php 

namespace App\Http\Controllers; 

use Auth; 
use App\Http\Requests; 
use Illuminate\Http\Request; 

class HomeController extends Controller 
{ 
    /** 
    * Create a new controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('auth'); 
    } 

    /** 
    * Show the application dashboard. 
    * 
    * @return \Illuminate\Http\Response 
    */ 

    public function index() 
    { 
     if(Auth::check()) { 
      return view('home'); 
     } 

     return view('auth/login'); 
    } 
} 

HomeController.php索引功能相當striaght前進。感謝所有幫助

回答

0

你在你的路由文件中犯了一個錯誤。你的路由文件應

<?php 

/* 
|-------------------------------------------------------------------------- 
| Application Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register all of the routes for an application. 
| It's a breeze. Simply tell Laravel the URIs it should respond to 
| and give it the controller to call when that URI is requested. 
| 
*/ 

Route::get('/', function() { 
    return view('welcome'); 
}); 

// Authentication routes 
Route::get('auth/login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 
Route::get('auth/logout', 'Auth\[email protected]'); 

// Registration routes 
Route::get('auth/register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 
Route::controllers(['password' => 'Auth\PasswordController',]); 

Route::get('/home', '[email protected]'); 

// Using A Route Closure 
Route::get('profile', ['middleware' => 'auth', function() { 
    // Only authenticated users may enter... 
    Route::auth(); 
}]); 

希望這將解決你的問題

0

如果您使用Laravel的認證模塊,以減輕你的工作,你應該看看這裏https://laravel.com/docs/5.2/authentication#authentication-quickstart

你會能夠定義您自己的重定向和路徑。

您可能還需要

  • 檢查Http/Middlewares文件夾下你的Authenticate.php中間件,你會發現客人重定向有
  • 在您所設定的'auth'中間件你HomeController.php構造,因此任何人誰訪問/home並沒有登錄會被重定向到Authenticate.php中間件

現在,從我自己的經驗,我會建議設置的URL喲使用Laravel的身份驗證助手可以更快地移動,這些構建得很好,可以安全地使用,而不是重新構建輪子,你知道嗎?

構建您自己的身份驗證過程可能會很無聊,除非您想讓代碼和測試變得骯髒。