Laravel 怎么给$request添加数据?

1、laravel 怎么给$request添加数据?

$request中源码有一个merge方法,将一个新值合并到request中:

/**
     * Merge new input into the current request's input array.
     *
     * @param  array  $input
     * @return void
     */
    public function merge(array $input)
    {
        $this->getInputSource()->add($input);
    }

所以我们可以使用:

$request->merge(['newKey' => 'newValue']);

获取:

$request->newKey;
$request->input('newKey);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-05
  • 2021-06-24
  • 2021-04-24
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案