gpt4 book ai didi

php - Laravel 如何测试 Controller 中的复选框是否被选中

转载 作者:可可西里 更新时间:2023-11-01 13:38:24 32 4
gpt4 key购买 nike

我试图获取复选框是否被选中:

在我看来:

<form data-toggle="validator" data-disable="false" role="form" action="/admin/role/add" method="post">
<div class="checkbox checkbox-success">
<input name="test" id="test" type="checkbox" value="test">
<label for="test" style="padding-left: 15px!important;">test</label>
</div>
</form>
<form data-toggle="validator" data-disable="false" role="form" action="/admin/role/add" method="post">
{{ csrf_field() }}
<div class="form-group pull-right">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>

在我的 Controller 中:

public function createRole(Request $request)
{
if($request->has('test')) {
new \App\Debug\Firephp('test', ['test' => true]);
}
}

在我的 web.php 中:

Route::post('/admin/role/add', 'AdminController@createRole')

但由于某些原因不起作用。

我该怎么做?

感谢回复。

编辑 1:

这是我的表单构建不当。

最佳答案

你可以用它来测试:

if( Input::get('test', false) ) {
// there is something for 'test'
} else {
// there was no 'test' or it was false
}

或者

if( Request::input('test') ) { //...

或者

public function store(Request $request)
{
if( $request->has('test') ){
//...
}
}

https://laravel.com/docs/5.0/requests

关于php - Laravel 如何测试 Controller 中的复选框是否被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40411283/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com