2016-07-01 64 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的身份验证助手可以更快地移动,这些构建得很好,可以安全地使用,而不是重新构建轮子,你知道吗?

构建您自己的身份验证过程可能会很无聊,除非您想让代码和测试变得肮脏。