简体   繁体   English

从控制器Laravel 5.2在$ request-> input()中注入值

[英]Inject values in $request->input() from controller Laravel 5.2

Is there a way to do something like this in the controller? 有没有办法在控制器中执行类似的操作?

$request->input(['new_field_name' => 'new_val']);

I've googled a lot, but the only thing I've found was related to Laravel's 4.x formatInput method, which has been removed from the 5.x 我已经在Google上进行了很多搜索,但是我发现的唯一内容与Laravel的4.x formatInput方法有关,该方法已从5.x中删除。

I need to inject a specific field in the $request when the request has passed the validation, then save the new record in the db. 当请求通过验证时,我需要在$ request中注入特定字段,然后将新记录保存在db中。

Any clue? 有什么线索吗? Thanks to everyone! 谢谢大家!

Method merge is the right tool for this. 方法merge是正确的工具。

Example of a typical use case (saving a slug given a title): 典型用例的示例(保存带有标题的子弹):

$request->merge(['slug' => Str::slug($request->title)]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM