简体   繁体   English

Laravel 5.1名称路由错误

[英]Laravel 5.1 name routes error

I need your help for something I not understand. 对于某些我不了解的事情,我需要您的帮助。

I am learning Laravel with a few tutorials (in spanish, my language) from this page: https://styde.net/proyectos/ 我正在通过此页面上的一些教程(西班牙语,我的语言)来学习Laravel: https ://styde.net/proyectos/

First I done the Curso básico de Laravel 5 without problem ( link to tutorial ). 首先,我毫无问题地完成了Cursobásicode Laravel 5链接到教程 )。 But now, I am doing Curso de Laravel 5.1 ( link to tutorial ) I found a problem. 但是现在,我在做Curso de Laravel 5.1链接到教程 )时发现一个问题。

On third point on first part, shows how Laravel add routes into routes.php . 在对第一部分第三点,显示Laravel如何添加路由到routes.php文件

I have this url (copied from Laravel documentation) and works fine: 我有这个URL(从Laravel文档复制),并且工作正常:

Route::get('auth/login', 'Auth\AuthController@postLogin');

But the teacher shows how make a change. 但是老师展示了如何做出改变。 He removes the 'auth/', being the new code this: 他删除了“ auth /”,这是新的代码:

Route::post('login', 'Auth\AuthController@postLogin');

After, he shows how to use 'names' and he makes other change: 之后,他展示了如何使用“名称”,并进行了其他更改:

Route::get('login', [
'uses'  => 'Auth\AuthController@getLogin',
'as'    => 'login'
]);

He goes to form, and change the action by 他去形成,并通过改变行为

{{ route('login') }}

Finally he clicked on button (the form is for login, only email and password). 最后,他单击了按钮(表单用于登录,仅用于电子邮件和密码)。

The response shows the errors: email and password are empty. 响应显示错误:电子邮件和密码为空。 It's ok. 没关系。

But I have a important error: 但是我有一个重要的错误:

MethodNotAllowedHttpException in RouteCollection.php line 201:

错误截图

Can someone help, please? 有人可以帮忙吗? Than you!! 比你!!

You have Route::get , but i think it should be Route::post . 您有Route::get ,但我认为应该是Route::post

MethodNotAllowedHttpException says that You make wrong type request (eg. trying make POST to GET route) MethodNotAllowedHttpException表示您输入了错误的类型请求(例如,尝试使POST到GET路由)

I think you need two routes: 我认为您需要两条路线:

Route::get('login', array(
   'uses'  => 'Auth\AuthController@getLogin',
   'as'    => 'getLogin'
));

Route::post('login', array(
   'uses'  => 'Auth\AuthController@postLogin',
   'as'    => 'postLogin'
));

To go to login page use URL::route('getLogin') and in form action use URL::route('postLogin'); 要进入登录页面,请使用URL::route('getLogin') ,在表单操作中请使用URL::route('postLogin'); and make sure you have this 2 methods inside Auth\\AuthController! 并确保您在Auth \\ AuthController中拥有这2个方法! getLogin performs return of the view, and postLogin post data for login process! getLogin执行视图的返回,并为登录过程发布postLogin发布数据!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM