中间件的使用疑问

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

$request->age <= 200 

获取值

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

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

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

你把变量设置在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);
        });
    }
5年前 评论
bing (楼主) 5年前
讨论数量: 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);
        });
    }
5年前 评论
bing (楼主) 5年前
$request->request->add();
$request->query->add()
5年前 评论
自由与温暖是遥不可及的梦想
$request->user()->id
// 这样可以获取到用户id 
// $request->user() 可以获取到用户的模型
5年前 评论

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

5年前 评论

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