【问题标题】:Laravel call route from controller来自控制器的 Laravel 调用路由
【发布时间】:2016-06-15 03:16:58
【问题描述】:

成功登录后我正在调用getting_started路由:

protected $redirectTo = '/getting_started';

这是我的getting_started路线代码:

Route::get('/getting_started','UserController@getting_started');

和控制器代码:

public function getting_started()
{
    $id= Auth::id();
    $user = DB::table('user_profiles')->where('user_id', '=', $id)->first();

    if($user->dashboard_access == 0)
    {
        DB::table('user_profiles')
            ->where('user_id', $id)
            ->update(['dashboard_access' => 1]);
        return view('user.getting_started');
    }

    return view('user.dashboard');
}

它完美地工作并显示在 url 中:

http://localhost:8080/getting_started

现在我真的希望如果 user.dashboard 视图被称为它在 url 中显示,例如:

http://localhost:8080/dashboard`

并在getting_started 观看节目:

http://localhost:8080/getting_started

可以调用仪表板路由而不是:

  return view('user.dashboard');

我的 dashobard 路线是:

Route::get('/dashboard',['middleware' => 'auth', function () {
    return view('user.dashboard');
}]);

【问题讨论】:

    标签: php laravel laravel-5 routes laravel-5.2


    【解决方案1】:

    我的理解是你要找的是这个功能

    return redirect()->route('dashboard');

    我对您的问题的理解可能是错误的。也许你在问别的。

    【讨论】:

      【解决方案2】:

      那个叫做 Redirection 并且特别是你想要 Returning A Redirect To A Named Route,你的路由叫做 user.dashboard 所以你可以使用 redirect()->route(route_name) 重定向到它: p>

      return redirect()->route('user.dashboard');
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2017-02-10
        • 2018-06-10
        • 2014-02-06
        • 2016-11-10
        • 2017-08-03
        • 2015-10-02
        • 2018-01-09
        • 2014-07-20
        • 1970-01-01
        相关资源
        最近更新 更多