中间件的使用疑问

中间件《Laravel 7 中文文档》
手册中可以这样

$request->age <= 200 

获取值

我按图中这样操作就不行 获取不到值
中间件的使用疑问

求解惑,或给出文档出处
我再去仔细看看

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
最佳答案

你把变量设置在 attributes 里面,调用 get () 方法时会获取到 attributes

Symfony\Component\HttpFoundation\Request
public function get($key, $default = null)
{
    if ($this !== $result = $this->attributes->get($key, $this)) {
        return $result;
    }

    if ($this !== $result = $this->query->get($key, $this)) {
        return $result;
    }

    if ($this !== $result = $this->request->get($key, $this)) {
        return $result;
    }

    return $default;
}

使用 ->user_info 时调用__get () 方法 Get an input element from the request. 并不会获取 attributes 的值

 Illuminate\Http\Request
   public function __get($key)
    {
        return Arr::get($this->all(), $key, function () use ($key) {
            return $this->route($key);
        });
    }
4年前 评论
bing (楼主) 4年前
讨论数量: 4

你把变量设置在 attributes 里面,调用 get () 方法时会获取到 attributes

Symfony\Component\HttpFoundation\Request
public function get($key, $default = null)
{
    if ($this !== $result = $this->attributes->get($key, $this)) {
        return $result;
    }

    if ($this !== $result = $this->query->get($key, $this)) {
        return $result;
    }

    if ($this !== $result = $this->request->get($key, $this)) {
        return $result;
    }

    return $default;
}

使用 ->user_info 时调用__get () 方法 Get an input element from the request. 并不会获取 attributes 的值

 Illuminate\Http\Request
   public function __get($key)
    {
        return Arr::get($this->all(), $key, function () use ($key) {
            return $this->route($key);
        });
    }
4年前 评论
bing (楼主) 4年前
$request->request->add();
$request->query->add()
4年前 评论
自由与温暖是遥不可及的梦想
$request->user()->id
// 这样可以获取到用户id 
// $request->user() 可以获取到用户的模型
4年前 评论

@自由与温暖是遥不可及的梦想 谢谢回答,虽然不是我想要的,但也教会了我一招 :thumbsup: :thumbsup:

4年前 评论