当我通过 POST 方法发送我的表单时,我需要检查复选框是否被选中。在我的控制器中,我有 4 个 if 是我检查的地方,但是当我这样做时,我会出错
非法的运算符和值组合。
我的看法
{!! Form::open(['action' => 'PersonsController@raport', 'method' => 'POST']) !!}
@csrf
<div class="form-group">
<label for="exampleFormControlFile1">Personel:</label>
<input class="form-control form-control-sm" type="text" name="data" id="data" value="{{date('Y-m-01')}}" width="100%" readonly/>
{!! $errors->first('data', '<strong><p style="color:red;" class="help-block">:message</p></strong>') !!}
<div class="form-check">
<input class="form-check-input" name="all" type="checkbox" value="1" id="all">
<label class="form-check-label" for="defaultCheck1">
All
</label>
</div>
</div>
<div class="form-group">
<label for="exampleFormControlFile1">User </label>
{!! Form::select('users', $users, null, ['class'=>'form-control form-control-sm', 'placeholder'=>'All users']) !!}
{!! $errors->first('users', '<strong><p style="color:red;" class="help-block">:message</p></strong>') !!}
</div>
{{Form::submit('Raport', ['class'=>'btn btn-primary btn-sm'])}}
{!! Form::close() !!}
和控制器
public function raport(Request $request)
{
//... some code
if($request->input('all') !== 'on' && empty($request->input('users')))
{
$raport = Users::where('data', '>=', $request->input('data'))
->orderBy('id_users', 'asc')->get();
}
elseif($request->input('all') === 'on' && !empty($request->input('users')))
{
$raport = Users::where('id_users', $request->input('users'))
->orderBy('id_users', 'asc')->get();
}
}
慕姐4208626
慕尼黑的夜晚无繁华
杨__羊羊