使用laravel 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\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
// Registration routes
Route::get('register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
Route::controllers(['password' => 'Auth\PasswordController',]);
Route::get('/home', 'HomeController@index');
// 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
索引功能非常严格。感谢所有帮助
答案 0 :(得分:0)
Route::get('login', 'Auth\AuthController@getLogin');
应该是
Route::get('auth/login', 'Auth\AuthController@getLogin');
答案 1 :(得分:0)
你在Routes文件中犯了一个错误。您的路线文件应为
<?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\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
// Registration routes
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
Route::controllers(['password' => 'Auth\PasswordController',]);
Route::get('/home', 'HomeController@index');
// Using A Route Closure
Route::get('profile', ['middleware' => 'auth', function() {
// Only authenticated users may enter...
Route::auth();
}]);
希望这可以解决您的问题
答案 2 :(得分:0)
如果您正在使用Laravel的身份验证模块来简化工作,那么您应该看看https://laravel.com/docs/5.2/authentication#authentication-quickstart
您将能够定义自己的重定向和路径。
你可能也想
Authenticate.php
文件夹下的Http/Middlewares
中间件,您会发现访客重定向HomeController.php
构造函数中,您设置了'auth'中间件,因此访问/home
且未记录的任何人都将被重定向到Authenticate.php
中间件中设置的网址根据我自己的经验,我建议你使用Laravel的身份验证助手更快地移动,这些是精心构建的,使用安全而不是重新构建轮子,你知道吗?
构建您自己的身份验证过程可能会非常无聊,除非您想亲自处理代码和测试。