laravel - 有没有办法将值插入请求(Laravel5)
问题描述
当我保存帖子时,如果帖子为空,我想将其他内容设为默认值。
换句话说,在下面的代码中,"$request->content"
是null
.
if (($request->content) == null)
{
$request->request->add(['content', $request->other_content]);
}
dd($request->content);
我已经运行了我的代码,但结果"dd($ request->content)"
仍然是null
.
怎么了?
提前感谢您的帮助。
解决方案
在您的代码中添加您的请求['content', $request->other_content]
2 值。但它必须是['content' => $request->other_content]
试试这个更正的代码
if (($request->content) == null) {
$request->request->add(['content' => $request->other_content]);
}
推荐阅读
- ruby-on-rails - rspec 流程无法理解
- html-select - 如何在 HTML.DropDownList 中将 id 设置为选项
- php - 在 docker php 容器中找不到 MySQLi
- python-3.x - tf.layers.dense() 和 tf.contrib.layers.fully_connected() 有什么区别?
- php - ldap_add():添加:推荐
- google-cloud-platform - 没有足够的资源来满足请求尝试不同的区域
- java - 在重新添加之前立即从 HashSet 中删除元素有什么可能的原因?
- django - Django + Nginx 将上传的文件保存到其他服务器和反向文件
- google-app-engine - GAE,这很可能会导致新进程用于对您的应用程序的下一个请求
- python - Python re.match:如何进行特定的“或”匹配