如何在laravel中找到复选框的状态?我想根据复选框的状态执行请求。这就是我目前正在做的事情。
然后只有代码的else部分继续运行。我做错了什么?
if(Input::get('check', false))
{
//do this
}
else
{
//do that
}
更新
$test = new Test(array(
'id' => $no,
$checkbox = $request['myCheck'] ? 1 : 0;
if ($checkbox == 1)
{
$set_amt= $label- $figure;
} else {
$set_amt = $get_all;
}
'amount' => $amount,
答案 0 :(得分:3)
您可以在控制器中执行此操作:
public function store(Request $request)
{
$checkbox = $request['check'] ? 1 : 0;
if ($checkbox == 1)
{
//
} else {
//
}
}
在你看来,你是这样的:
{!! Form::label('check', 'Checkbox Label: ')!!}
{!! Form::check('check', null, isset($model_name) ? $model_name->check : 0, ['class' => 'form-control' ]) !!}
如果您不使用表单外观,那么在视图中执行此操作:
<label for="check">Checkbox Label: </label>
<input class="form-control"
value="1"
name="check"
type="checkbox"
@if(isset($model) && $model->check == 1) checked @endif
>
我不知道你想要达到什么目标,所以我现在只是猜测:
public function store(Request $request)
{
$checkbox = $request['myCheck'] ? 1 : 0;
// I can't see in your code what are these so I just
// guessed that they are maybe part of $request:
$set_amt = null;
$label = $request['label'];
$figure = $request['figure'];
$get_all = $request['get_all'];
if ($checkbox == 1)
{
$set_amt = $label - $figure;
} else {
$set_amt = $get_all;
}
$test = new Test([
'id' => $no,
'set_amt' => $set_amt,
'amount' => $amount
]);
$test->save();
return redirect('/your_route_name');
}
我希望这会对你有所帮助。