2015-12-07 140 views
0

我的控制器的操作方法是象下面这样:复选框值 - Laravel

public function store(Request $request) 
{ 
    $IsActive = $request->input('IsActive'); 
    echo $IsActive; 
    die(); 
} 

我的看法是像下面

{!! Form::open(array('method' => 'POST', 'action' => '[email protected]')) !!} 
    {!! Form::checkbox('IsActive', 0, null, array('class' => "flat")) !!} 
    {!! Form::submit('Save', array('class' => "btn btn-success"))!!} 
{!! Form::close() !!} 

问题

在表单提交中,我总是得到CheckBox的值= 0。我是否缺少 的东西?

回答

1

您得到0作为表单提交的值是因为您已明确声明值为0。将0替换为您想要的任何值,然后按照您的愿望获得结果。

api source code

/** 
* Create a checkbox input field. 
* 
* @param string $name 
* @param mixed $value 
* @param bool $checked 
* @param array $options 
* @return string 
*/ 
public function checkbox($name, $value = 1, $checked = null, $options = array()) 
{ 
    return $this->checkable('checkbox', $name, $value, $checked, $options); 
} 

/** 
* Create a checkable input field. 
* 
* @param string $type 
* @param string $name 
* @param mixed $value 
* @param bool $checked 
* @param array $options 
* 
* @return string 
*/ 
protected function checkable($type, $name, $value, $checked, $options) 
{ 
    $checked = $this->getCheckedState($type, $name, $value, $checked); 
    if ($checked) { 
     $options['checked'] = 'checked'; 
    } 
    return $this->input($type, $name, $value, $options); 
} 

希望这有助于你出去。