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

Laravel 意外重定向(302)

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

問題描述

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

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 創(chuàng)建的內(nèi)置 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.

此外,雖然幾乎所有頁面(此處未列出)都按預(yù)期工作,但 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,如果這有任何區(qū)別

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

我通過調(diào)試欄發(fā)現(xiàn)了重定向.知道要尋找什么嗎?

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

推薦答案

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

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,但發(fā)現(xiàn)將其移出 AuthController 并移入 UserController(它應(yīng)該從一開始的位置)修復(fù)了行為.

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.

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

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']);

    [...]
    });
});

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

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

相關(guān)文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數(shù))
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數(shù)中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應(yīng)內(nèi)容必須是實現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動到 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())
主站蜘蛛池模板: 亚洲精品一区国语对白 | 久久久蜜桃一区二区人 | 欧美日韩一卡二卡 | 国产精品99久久久久久久久久久久 | 久久精品中文字幕 | 国产精品久久久久久吹潮日韩动画 | 亚洲精品一二三区 | 免费看a| av国产精品毛片一区二区小说 | 国产91在线 | 欧美 | 国产毛片久久久久久久久春天 | 久草在线| 国产日韩欧美一区二区在线播放 | 欧美在线视频网 | 午夜精品一区二区三区在线观看 | 欧美精品一区二区三区在线 | 国产一区二区三区 | 91一区二区在线观看 | 欧美涩| 一区二区三区欧美 | 在线欧美激情 | 国产成人精品一区 | 久久影音先锋 | 精品久久久久久久久久 | 日韩精品一区二区三区在线观看 | 国产精品国产三级国产aⅴ无密码 | 99久久精品免费看国产四区 | 国产九一精品 | 毛片一区二区 | 日韩播放| 黑人一级黄色大片 | 91麻豆精品国产91久久久更新资源速度超快 | www国产成人免费观看视频,深夜成人网 | 午夜伦4480yy私人影院 | 日韩在线第一 | 亚洲午夜视频 | 99久久久久久99国产精品免 | 国产日韩精品一区 | 欧美精品一区二区三区一线天视频 | 亚洲 欧美 日韩 在线 | 老司机午夜性大片 |