久久久久久久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久久久久久久久久久 | 宅男噜噜噜66一区二区 | 亚洲国产一区二区三区在线观看 | 久久狼人天堂 | 天堂成人国产精品一区 | 欧美日韩不卡合集视频 | 中文字幕在线一区二区三区 | 免费久久视频 | 国产综合精品一区二区三区 | 亚洲高清视频一区二区 | 久久精品视频亚洲 | 一级免费毛片 | 欧美不卡| 偷牌自拍 | 日日夜夜狠狠操 | 精品自拍视频在线观看 | 国产成人精品综合 | 国产精品久久久久久久久久了 | 国产玖玖 | 精品一区国产 | 久久精品毛片 | 在线中文字幕第一页 | 特级黄一级播放 | 久草综合在线视频 | 成人精品视频 | 免费国产视频在线观看 | 国产a级毛片 | 精品久久99 | 久久国产一区二区三区 | 国产一区中文字幕 | 黄色成人在线观看 | 中文字幕欧美一区 | 性欧美hd| 日韩小视频在线 | 欧美精品一二三 | 亚洲中午字幕 | 国产午夜视频 | 国产激情在线 | 日韩在线 | 欧美大片黄 | 日本精品一区二区三区在线观看视频 |