Laravel 怎么给$request添加数据?


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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM