中间件的使用疑问

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

$request->age <= 200 

获取值

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

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

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

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

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

3年前 评论

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