Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在更新Eloquent时处理Form::checkbox?_Php_Laravel_Eloquent - Fatal编程技术网

Php 如何在更新Eloquent时处理Form::checkbox?

Php 如何在更新Eloquent时处理Form::checkbox?,php,laravel,eloquent,Php,Laravel,Eloquent,我正在努力更新某个模型。该模式具有变量'boolean\u new\u frame'。此值可以是0或1。不过,laravel表单的配置不起作用。在做了一些研究之后,我现在拥有的代码将值保持在0 表格: <div class="form-group"> {!! Form::label('boolean_new_frame', 'Pagina openen in nieuw venster?') !!} {!! Form::hidden('boolean_new_fram

我正在努力更新某个模型。该模式具有变量
'boolean\u new\u frame'
。此值可以是
0
1
。不过,laravel表单的配置不起作用。在做了一些研究之后,我现在拥有的代码将值保持在
0

表格:

<div class="form-group">
    {!! Form::label('boolean_new_frame', 'Pagina openen in nieuw venster?') !!}
    {!! Form::hidden('boolean_new_frame', false) !!}
    {!! Form::checkbox('boolean_new_frame', null, ['class' => 'form-control']) !!}
</div>

有人能帮我调整表单/控制器,使“
boolean\u new\u frame”
变量正确更新

您可以与默认值连接,因为未选中复选框时,该复选框没有输入项:

更新(重新阅读问题):


您使用的是什么版本的Laravel?对不起,使用Laravel 5.1$checkbox=Input::get('boolean_new_frame')@dsadnick,然后
$rule['boolean\u new\u frame]=$checkbox
?因为这不起作用..您是否向模型上的可填充属性添加了“boolean\u new\u frame”<代码>$fillable=['boolean\u new\u frame']?我尝试了此代码并选中了该框,但数据库仍然显示该值为0..@AnnaJeanine我似乎把它放错了方向我现在正在查看您更新的答案,但我希望保留
“null”
在我的表单中,因为这会根据用户想要更新的选定项目设置默认值。然后像我的问题一样保留表单?这就是想法。
public function update($id) {
  $rule  = Model::findOrFail($id);
  $input = \Input::except(['true_mail_attachment']);

  $rule->update($input);

  return \Redirect::route('admin.rules')
    ->with('message', 'Good!');
}
$input["boolean_new_frame"] = !array_key_exists("boolean_new_frame",$input)?0:1;
$rule->update($input);