[英]laravel 5.1 routes error message
使用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
索引功能相当不错。 谢谢你的帮助
Route::get('login', 'Auth\AuthController@getLogin');
应该
Route::get('auth/login', 'Auth\AuthController@getLogin');
您在路线文件中输入了错误。 您的路线文件应为
<?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();
}]);
希望这可以解决您的问题
如果您使用Laravel的身份验证模块简化工作,则应在此处查看https://laravel.com/docs/5.2/authentication#authentication-quickstart
您将能够定义自己的重定向和路径。
您可能还想
Http/Middlewares
文件夹下的Authenticate.php
中间件,您会在此找到访客重定向 HomeController.php
构造函数中,您已经设置了“ auth”中间件,因此任何访问/home
且未登录的人都将被重定向到Authenticate.php
中间件中设置的URL。 现在,根据我自己的经验,我建议您使用Laravel的身份验证帮助程序来加快移动速度,因为它们结构合理且使用安全,而不是重新构造轮子,您知道吗?
除非您想通过编写代码和进行测试,否则构建自己的身份验证过程可能会很无聊。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.