中间件的使用疑问

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

$request->age <= 200 

获取值

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

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

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
最佳答案

你把变量设置在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年前 评论

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