最佳答案
你把变量设置在 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);
});
}
讨论数量:
你把变量设置在 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);
});
}
推荐文章: