2017-10-20 76 views
0

无论如何删除空窗体值表单request-> all()方法? 这就是我想要做的更新,换句话说只有后填充表单值。使用laravl5忽略更新时的空表单值

$data = request()->except(['_token','id']); 

DB::table($table)->where('id',$id)->update($data); 

注:我已动态生成的列,所以我想我不能在使用这些列除了参数列表中。

此更新该行的所有列,但我只想更新那些列的值是装载和剩余的列/字段保持相同的旧值

回答

1

看一看array_filter

// All posted data except token and id 
$data = request()->except(['_token','id']); 

// Remove empty array values from the data 
$result = array_filter($data); 

// update record 
DB::table($table)->where('id', $arr)->update($result); 

希望这会有所帮助。