久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel 意外重定向(302)

Laravel unexpected redirects ( 302 )(Laravel 意外重定向(302))
本文介紹了Laravel 意外重定向(302)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經開始了一個新的 Laravel 5.2 項目,使用 laravel new MyApp,并通過 php artisan make:auth 添加了身份驗證.這是一個僅限會員的網站,第一個用戶在其中被播種,然后創建其余用戶(無需手動創建用戶/密碼重置等).

I have started a new Laravel 5.2 project, using laravel new MyApp, and added authentication via php artisan make:auth. This is intended to be a members only website, where the first user is seeded, and creates the rest (no manual user creation/password reset/etc).

這些是我目前定義的路由:

These are the routes I have currently defined:

 Route::group(['middleware' => 'web'], function () {
  // Authentication Routes...
  Route::get( 'user/login',  ['as' => 'user.login',     'uses' => 'AuthAuthController@showLoginForm']);
  Route::post('user/login',  ['as' => 'user.doLogin',   'uses' => 'AuthAuthController@login'        ]);

  Route::group(['middleware' => 'auth'], function() {
    // Authenticated user routes
    Route::get( '/', ['as'=>'home', 'uses'=> 'HomeController@index']);
    Route::get( 'user/{uid?}', ['as' => 'user.profile',   'uses' => 'AuthAuthController@profile' ]);
    Route::get( 'user/logout', ['as' => 'user.logout',    'uses' => 'AuthAuthController@logout'  ]);
    Route::get( '/user/add',   ['as' => 'user.add',       'uses' => 'AuthAuthController@showAddUser']);

    [...]
  });
});

我可以正常登錄,但是我遇到了一些非常奇怪"的行為 - 當我嘗試注銷時(通過通過 artisan 創建的內置 logout 方法),頁面做了一個 302 重定向到主頁,我仍然登錄.

I can login just fine, however I'm experiencing some very "funky" behavior - when I try to logout ( via the built-in logout method that was created via artisan ), the page does a 302 redirect to home, and I am still logged in.

此外,雖然幾乎所有頁面(此處未列出)都按預期工作,但 user.add 也會向主頁生成 302.

What's more, while almost all pages (not listed here) work as expected, user.add also produces a 302 to the home page.

請注意主頁向 AuthController 聲明為 $redirectTo,如果這有任何區別

Do note the homepage is declared to the AuthController as $redirectTo, if that makes any difference

我通過調試欄發現了重定向.知道要尋找什么嗎?

I found out about the redirects via the debugbar. Any idea on what to look for ?

推薦答案

經過幾個小時的摸索,我找到了答案——這很愚蠢.

After several hours of hair pulling, I have found my answer -- and it's silly.

問題是路由 user.profile 有一個路徑 user/{uid?} 并且它匹配 user/logoutuser/add 作為路徑.

The problem is that the route user.profile has a path user/{uid?} and it matches both user/logout and user/add as paths.

它在其他人之前,沒有正則表達式或類似的,它處理了路線.

It being before the others, and not having a regex or similar, it handled the route.

我仍然不知道為什么會為 那個 頁面生成 302,但發現將其移出 AuthController 并移入 UserController(它應該從一開始的位置)修復了行為.

I still don't know why a 302 was generated for that page, but found that moving it out of the AuthController and into the UserController (where it should be from the start) fixed the behavior.

因此,我的(修改和工作)路線現在看起來像這樣:

Thus, my (amended and working) routes now look like so:

Route::group(['middleware' => 'web'], function () {
  // Authentication Routes...
  Route::get( 'user/login',  ['as' => 'user.login',     'uses' => 'AuthAuthController@showLoginForm']);
  Route::post('user/login',  ['as' => 'user.doLogin',   'uses' => 'AuthAuthController@login'        ]);

  Route::group(['middleware' => 'auth'], function() {
    // Authenticated user routes
    Route::get( '/',     ['as'=>'home', 'uses'=> 'HomeController@index']);
    Route::get( '/home', ['as'=>'home', 'uses'=> 'HomeController@home']);
    Route::get( 'user/logout', ['as' => 'user.logout',    'uses' => 'AuthAuthController@logout'  ]);

    // *** Added /profile/ here to prevent matching with other routes ****
    Route::get( 'user/profile/{uid?}', ['as' => 'user.profile',   'uses' => 'UserController@profile' ]);
    Route::get( '/user/add',           ['as' => 'user.add',       'uses' => 'UserController@showAddUser']);

    [...]
    });
});

這篇關于Laravel 意外重定向(302)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 国产一区二区激情视频 | 国产一区二区不卡 | 91电影| 国产亚洲精品91 | 亚洲 中文 欧美 | 久久久久国产精品 | 久久国内 | 黑人中文字幕一区二区三区 | 一级一片在线观看 | 午夜影院在线观看 | 日韩一区二区成人 | 欧美黄色录像 | 九色国产 | 成年人网站免费 | 午夜精品 | 中文字幕 欧美 日韩 | 久久久久久国产精品免费免费 | 鸡毛片 | 99精品久久 | 日本不卡一区二区三区 | 欧美性jizz18性欧美 | 欧美日韩一区在线 | 欧美黄视频 | 国产激情毛片 | www视频在线观看 | 免费国产网站 | 色综合久久88色综合天天 | 51ⅴ精品国产91久久久久久 | 午夜欧美一区二区三区在线播放 | 成人午夜免费福利视频 | 亚洲精品无人区 | 亚洲一区二区在线播放 | 97高清国语自产拍 | 亚洲欧美aⅴ | 91精品国产乱码久久蜜臀 | 欧美一级片免费看 | 一级看片 | 免费h在线| 亚洲入口| 成人免费视频观看 | 亚洲精品在线视频 |