为什么不解答一下这个简写?

return redirect('login');
我相信应该等同于下面吧?好像没有解释一下,为什么可以这么写redirect('login'),这个参数对应的是路由name?
return redirect()->route('login');

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 6

不是你理解的那样,redirect的第一个参数是path,只是login路由的namepath刚好是一样而已。

辅助函数redirect,通过服务容器实例化了一个Redirector类,然后调用了类的to方法

function redirect($to = null, $status = 302, $headers = [], $secure = null)
{
    if (is_null($to)) {
        return app('redirect');
    }

    return app('redirect')->to($to, $status, $headers, $secure);
}

to方法,第一个参数是path,也就是域名后面的路径/login

public function to($path, $status = 302, $headers = [], $secure = null)
{
    return $this->createRedirect($this->generator->to($path, [], $secure), $status, $headers);
}
5年前 评论
gh54gbvwsff4 2年前
FMW (作者) 2年前

不是你理解的那样,redirect的第一个参数是path,只是login路由的namepath刚好是一样而已。

辅助函数redirect,通过服务容器实例化了一个Redirector类,然后调用了类的to方法

function redirect($to = null, $status = 302, $headers = [], $secure = null)
{
    if (is_null($to)) {
        return app('redirect');
    }

    return app('redirect')->to($to, $status, $headers, $secure);
}

to方法,第一个参数是path,也就是域名后面的路径/login

public function to($path, $status = 302, $headers = [], $secure = null)
{
    return $this->createRedirect($this->generator->to($path, [], $secure), $status, $headers);
}
5年前 评论
gh54gbvwsff4 2年前
FMW (作者) 2年前

@jltxwesley 居然比我快了两分钟...

5年前 评论
jltxwesley

@FMW

没必要发同样的 我删了 你的标准答案 😄

5年前 评论

@jltxwesley :joy: 留着也没啥关系

5年前 评论

代码跟踪一下就知道了

5年前 评论

看下源代码就知道了

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!