pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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())
主站蜘蛛池模板: 安规_综合测试仪,电器安全性能综合测试仪,低压母线槽安规综合测试仪-青岛合众电子有限公司 | 铝单板_铝窗花_铝单板厂家_氟碳包柱铝单板批发价格-佛山科阳金属 | 金属软管_不锈钢金属软管_巩义市润达管道设备制造有限公司 | 衬塑管道_衬四氟管道厂家-淄博恒固化工设备有限公司 | 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | 德国EA可编程直流电源_电子负载,中国台湾固纬直流电源_交流电源-苏州展文电子科技有限公司 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | IP检测-检测您的IP质量| 广州小程序开发_APP开发公司_分销商城系统定制_小跑科技 | 德州网站开发定制-小程序开发制作-APP软件开发-「两山开发」 | 混合反应量热仪-高温高压量热仪-微机差热分析仪DTA|凯璞百科 | 山东限矩型液力偶合器_液力耦合器易熔塞厂家-淄博市汇川源机械厂 | 液晶拼接屏厂家_拼接屏品牌_拼接屏价格_监控大屏—北京维康 | 路斯特伺服驱动器维修,伦茨伺服驱动器维修|万骏自动化百科 | 校园文化空间设计-数字化|中医文化空间设计-党建|法治廉政主题文化空间施工-山东锐尚文化传播公司 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 间苯二酚,间苯二酚厂家-淄博双和化工 | 浴室柜-浴室镜厂家-YINAISI · 意大利设计师品牌 | 咿耐斯 |-浙江台州市丰源卫浴有限公司 | 胶泥瓷砖胶,轻质粉刷石膏,嵌缝石膏厂家,腻子粉批发,永康家德兴,永康市家德兴建材厂 | 耐腐蚀泵,耐腐蚀真空泵,玻璃钢真空泵-淄博华舜耐腐蚀真空泵有限公司 | 恒温恒湿箱(药品/保健品/食品/半导体/细菌)-兰贝石(北京)科技有限公司 | 打包钢带,铁皮打包带,烤蓝打包带-高密市金和金属制品厂 | 自动售货机_无人售货机_专业的自动售货机运营商_免费投放售货机-广州富宏主官网 | 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | MVE振动电机_MVE震动电机_MVE卧式振打电机-河南新乡德诚生产厂家 | AGV叉车|无人叉车|AGV智能叉车|AGV搬运车-江西丹巴赫机器人股份有限公司 | 合肥抖音SEO网站优化-网站建设-网络推广营销公司-百度爱采购-安徽企匠科技 | 气动隔膜泵厂家-温州永嘉定远泵阀有限公司 | 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 物流之家新闻网-最新物流新闻|物流资讯|物流政策|物流网-匡匡奈斯物流科技 | CPSE安博会| 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | 佛山市钱丰金属不锈钢蜂窝板定制厂家|不锈钢装饰线条|不锈钢屏风| 电梯装饰板|不锈钢蜂窝板不锈钢工艺板材厂家佛山市钱丰金属制品有限公司 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 上海橡胶接头_弹簧减震器_金属软接头厂家-上海淞江集团 | 河北中仪伟创试验仪器有限公司是专业生产沥青,土工,水泥,混凝土等试验仪器的厂家,咨询电话:13373070969 | 菲希尔X射线测厚仪-菲希尔库伦法测厚仪-无锡骏展仪器有限责任公司 | 沈阳建筑设计公司_加固改造设计_厂房设计_设计资质加盟【金辉设计】 | 点胶机_点胶阀_自动点胶机_智能点胶机_喷胶机_点胶机厂家【欧力克斯】 | DDoS安全防护官网-领先的DDoS安全防护服务商 | 北京遮阳网-防尘盖土网-盖土草坪-迷彩网-防尘网生产厂家-京兴科技 |