[英]How to save checkbox value to database Laravel
here's my form code : 这是我的表单代码:
<div class="form-group">
<label>Warranty:</label>
{{ Form::checkbox('warranty', 0, false) }}
</div>
here's my controller code : 这是我的控制器代码:
public function save(Request $request, $obj = null) {
if (!$obj) {
$obj = new Service;
}
(Input::has('warranty')) ? true : false;
return $this->saveHandler($request, $obj);
}
it throws this error Class 'App\\Http\\Controllers\\Input' not found 它将引发此错误类“ App \\ Http \\ Controllers \\ Input”
any idea ? 任何想法 ?
You can use request
object to get the warranty
input as: 您可以使用request
对象获取warranty
输入,如下所示:
$request->get('warranty')
or 要么
$request->has('warranty')
Input
facade was removed in latest verison, so you can add it to config/app.php
: Input
外观已在最新版本中删除,因此您可以将其添加到config/app.php
:
'Input' => Illuminate\Support\Facades\Input::class,
Or add this line to the beginning of a controller: 或将此行添加到控制器的开头:
use Illuminate\Support\Facades\Input;
Or write full path when you use it: 或在使用时写下完整路径:
(\Illuminate\Support\Facades\Input::has('warranty')) ? true : false;
将此添加到控制器的顶部,
use Illuminate\Support\Facades\Input;
$request->merge(array('checkbox_name' => $request->has('checkbox_name') ? true : false));
Object::create($request->all());
This is how I save boolean parameters which are checkboxes in form. 这就是我保存布尔参数(即复选框形式)的方式。
Or simply give your checkbox value 或简单地提供您的复选框值
{{ Form::checkbox('checkbox_name', 1) }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.