doukanhua0752 2015-10-06 05:24
浏览 63
已采纳

我们如何编辑Laravel Auth重定向网址?

In my project after authenticate the dashboard URL need to looks like "http://www.ct.dev/chistoper.martin_555/dashboard".

But now URL showing after authentication is "http://www.ct.dev/dashboard".

Please help me to edit url just like http://www.ct.dev/chistoper.martin_555/dashboard.

chistoper.martin_555 : I need to take this name from database.

AuthController.php

protected $redirectPath = '/dashboard';

routes.php

    Route::group(['middleware' => 'auth'], function () {
    Route::get('/dashboard', 'PublishprofileController@index');
});

PublishprofileController.php

public function index()
    {
        session()->put('userID', Auth::user()->id);
        $confirmDetails   = User::select('confirmed_at')
            ->where('id', session()->get('userID'))
            ->first();
        return view('test.frontend')->with('confirmTime', $confirmDetails->confirmed_at);
    }
  • 写回答

1条回答 默认 最新

  • drbz99867 2015-10-06 05:47
    关注

    Since you want your redirect path to be dynamic, this can be pretty complex and it might not even be possible. Instead you can do this in your PublishprofileController. This has the benefit of being more concise and can easily be changed down the line.

    public function index()
    {
        session()->put('userID', Auth::user()->id);
        $confirmDetails = User::select('confirmed_at')
            ->where('id', session()->get('userID'))
            ->first();
        return redirect(Auth::user()->name.'/dashboard');
    }
    

    Then in your routes.php:

    Route::get('{name}/dashboard', 'PublishprofileController@show');

    Then edit your show method to return the view. Obviously there's some more code you will have to write, that part is up to you, but this should get you on the right track

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?