有没有一种方法可以将值插入请求(Laravel5)

时间:2018-07-12 04:39:38

标签: laravel laravel-5 request

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

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

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

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

预先感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在代码中,您在请求中添加了<script type="text/javascript"> $(window).on("load",function(){ $.ajax({ type:'ajax', url:'<?php echo base_url('index.php/user_control/showdata/'); ?>', async:false, dataType:'json', success:function(data) { // console.log(data); var html=''; var i; for(i=0;i<data.length;i++) { html+='<tr>'+ '<td>'+data[i].uname+'</td>'+ '<td>'+data[i].email+'</td>'+ +'</tr>'; } $(".showid").html(html); }, error:function(data) { alert('ajax error'); } }); }); 2个值。但必须为['content', $request->other_content]尝试以下更正的代码

['content' => $request->other_content]
相关问题