我刚开始一个新的Laravel 5.2项目,我的路线出了问题。 Web中间件在路由列表中重复,我在会话和csrf方面遇到很多问题。
这是我的工匠路线:列表输出:
+--------+----------+----------------------------------+----------------------------+-----------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+----------------------------------+----------------------------+-----------------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web,web |
| | GET|HEAD | cron/cursos | cron_courses | App\Http\Controllers\CourseController@call_store | web,web |
| | GET|HEAD | cursos | courses | App\Http\Controllers\CourseController@index | web,web |
| | GET|HEAD | cursos/buscar | courses_search | App\Http\Controllers\CourseController@search | web,web |
| | GET|HEAD | cursos/detalle/{id} | courses_detail | App\Http\Controllers\CourseController@detail | web,web |
| | GET|HEAD | cursos/solicitar/{id} | courses_apply | App\Http\Controllers\CourseController@apply | web,web,auth |
| | POST | guardar-datos | save_panel | App\Http\Controllers\UserController@panel_save | web,web,auth |
| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | web,auth |
| | POST | login | | App\Http\Controllers\Auth\AuthController@login | web,guest |
| | GET|HEAD | login | | App\Http\Controllers\Auth\AuthController@showLoginForm | web,guest |
| | GET|HEAD | logout | | App\Http\Controllers\Auth\AuthController@logout | web |
| | GET|HEAD | panel | panel | App\Http\Controllers\UserController@panel | web,web,auth |
| | POST | password/email | | App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\PasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token?} | | App\Http\Controllers\Auth\PasswordController@showResetForm | web,guest |
| | GET|HEAD | prueba | prueba | App\Http\Controllers\UserController@prueba | web,web |
| | POST | register | | App\Http\Controllers\Auth\AuthController@register | web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\AuthController@showRegistrationForm | web,guest |
| | GET|HEAD | sociallogin/callback/{provider?} | auth.getSocialAuthCallback | App\Http\Controllers\AuthSocialController@getSocialAuthCallback | web,web |
| | GET|HEAD | sociallogin/{provider?} | auth.getSocialAuth | App\Http\Controllers\AuthSocialController@getSocialAuth | web,web |
+--------+----------+----------------------------------+----------------------------+-----------------------------------------------------------------+--------------+
这是我的routes.php文件:
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
Route::get('/prueba', ['as' => 'prueba', 'uses' => 'UserController@prueba']);
# HOME
Route::get('/cursos', ['as' => 'courses', 'uses' => 'CourseController@index']);
Route::get('/cursos/buscar', ['as' => 'courses_search', 'uses' => 'CourseController@search']);
Route::get('/cursos/detalle/{id}', ['as' => 'courses_detail', 'uses' => 'CourseController@detail']);
# SOCIAL LOGIN
Route::get('/sociallogin/{provider?}',[
'uses' => 'AuthSocialController@getSocialAuth',
'as' => 'auth.getSocialAuth'
]);
Route::get('/sociallogin/callback/{provider?}',[
'uses' => 'AuthSocialController@getSocialAuthCallback',
'as' => 'auth.getSocialAuthCallback'
]);
});
Route::group(['prefix' => 'cron', 'middleware' => ['web']], function () {
Route::get('/cursos', ['as' => 'cron_courses', 'uses' => 'CourseController@call_store']);
});
Route::group(['middleware' => ['web', 'auth']], function () {
Route::get('/panel', ['as' => 'panel', 'uses' => 'UserController@panel']);
Route::post('/guardar-datos', ['as' => 'save_panel', 'uses' => 'UserController@panel_save']);
Route::get('/cursos/solicitar/{id}', ['as' => 'courses_apply', 'uses' => 'CourseController@apply']);
});
Route::auth();
Route::get('/home', 'HomeController@index');
我在Laravel 5.2上有另一个项目,我一切正常。
知道怎么解决吗?
谢谢!
答案 0 :(得分:1)
您应该从web
删除routes.php
个中间件,因为since 5.2.27 Laravel applies web
middleware automatically to all routes in routes.php
。
答案 1 :(得分:0)
出于某种原因,您的routes.php文件中有一个额外的路由组。删除该路由组,它应该被修复。
Laravel使用'网络'默认情况下,中间件在最新版本的5.2中幕后操作!