【问题标题】:How can fix the change of my intended Website URL?如何修复我的预期网站 URL 的更改?
【发布时间】:2019-06-06 20:50:24
【问题描述】:

我为我的网站创建了一个身份验证。我发现如果用户已登录,他将无法返回主页,因为他现在在仪表板中。我在 Stackoverflow 的帮助下将所有内容从生成的 home.blade.php 更改为 dashboard.blade.php 以及 home 的所有相关引用

现在我遇到了一个尴尬的错误。如果我从仪表板注销并希望重定向到 http://localhost:8888/ (welcome.blade.php),我会得到 http://localhost:8888/login (login.blade.php)。

如果我在注销后单击左上角的导航品牌会更尴尬,我不会重定向到http://localhost:8888/,而是重定向到http://localhost:8888/login

  1. 我更改了 web.php 路由。我在“auth”和“guest”之间添加了组。
  2. 如果登录的用户试图将 url 从“/dashboard”操纵到“/”,他会被重定向。
  3. 我安装了 Laravel/telescope 是为了更好地查看错误,但对于初学者来说,这真的很令人困惑
  4. 我将 hone.blade.php 更改为 dashboard.blade.php 以及与“home”相关的所有内容
  5. 还试图找到解决方案并在用户注销后使用stackoverflow用户的代码进行重定向(LoginController.php),不起作用

web.php

Route::group(array(['middleware'=>['guest']]), function(){

  Route::get('/', function () {
    return view('welcome');
  });
});



Auth::routes();


// Only logged user
Route::group(array('middleware'=>'auth'), function(){
  Route::get('/dashboard', 'DashboardController@index')->name('dashboard');

  Route::get('/', function () {
    return redirect('/dashboard');
  });


});

登录控制器.php

use Illuminate\Http\Request;
protected function loggedOut(Request $request) {
      return redirect('/');
    }

所以我不能放望远镜的图片,但我想我可以尝试用文字重新创建图片。

预期结果:我对 HTTP-Status 了解不多,所以我做了所有 200

Verb| Path       | Status

Here by '/' should be viewed welcome.blade.php

GET | /          | 200

POST| /logout    | 200

GET | /dashboard | 200

The user can't visit the Path '/' because he is now in dashboard website.

GET | /          | 200

POST| /login     | 200

实际结果:

Verb| Path       | Status
GET | /login     | 200

GET | /          | 302

POST| /logout    | 302

GET | /dashboard | 200

GET | /          | 302

POST| /login     | 302

如果你们有任何问题并想看更多课程,请问我。我不知道与错误相关的内容。我的想法主要是web.php路由错误。

最好的问候 托比亚斯

【问题讨论】:

    标签: php laravel routing laravel-5.7 laravel-authentication


    【解决方案1】:

    错误是你两次使用同一条路线。

    在 web.php 中重写代码:

    Route::get('/', HomeController@index);
    
    Auth::routes();`
    
    // Only logged user
    Route::group(array('middleware'=>'auth'), function(){
        Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
    });
    

    并在 HomeController 中编写您的逻辑:

    public function index()
    {
        return Auth::guest() ? view('welcome') : redirect('/dashboard');
    }
    

    【讨论】:

      【解决方案2】:

      您是否检查了控制器或您预定家的路线。 例如在你的 web.php 中,我明白了,

          Route::get('/', function () {
          return view('welcome');
            });
          });
      

      然后在 auth 路由中

      Route::get('/', function () {
             return redirect('/dashboard');
            });
      

      【讨论】:

        猜你喜欢
        • 2017-02-05
        • 2021-12-24
        • 1970-01-01
        • 2013-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-05
        • 1970-01-01
        相关资源
        最近更新 更多