首页 > 解决方案 > 有没有办法将值插入请求(Laravel5)

问题描述

当我保存帖子时,如果帖子为空,我想将其他内容设为默认值。

换句话说,在下面的代码中,"$request->content"null.

if (($request->content) == null)
{
    $request->request->add(['content', $request->other_content]);
}
dd($request->content);

我已经运行了我的代码,但结果"dd($ request->content)"仍然是null.
怎么了?

提前感谢您的帮助。

标签: laravellaravel-5request

解决方案


在您的代码中添加您的请求['content', $request->other_content]2 值。但它必须是['content' => $request->other_content]试试这个更正的代码

if (($request->content) == null) {
    $request->request->add(['content' => $request->other_content]);
}

推荐阅读