简体   繁体   中英

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/

First I done the Curso básico de Laravel 5 without problem ( link to tutorial ). But now, I am doing Curso de Laravel 5.1 ( link to tutorial ) I found a problem.

On third point on first part, shows how Laravel add routes into routes.php .

I have this url (copied from Laravel documentation) and works fine:

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

But the teacher shows how make a change. He removes the 'auth/', being the new code this:

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 .

MethodNotAllowedHttpException says that You make wrong type request (eg. trying make POST to GET route)

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'); and make sure you have this 2 methods inside Auth\\AuthController! getLogin performs return of the view, and postLogin post data for login process!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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