我正在尝试检查是否有任何字段已被排除,如果没有已被排除,则返回错误页面。即使我填写了一个字段,它仍然会返回,就像没有选择任何字段一样。
控制器
public function getServices() {
$user = User::find(Auth::user()->id);
$input = [
'rooms' => Input::get('rooms'),
'pr_deodorizer' => Input::get('pr_deodorizer'),
'pr_protectant' => Input::get('pr_protectant'),
'pr_sanitizer' => Input::get('pr_sanitizer'),
'fr_couch' => Input::get('fr_couch'),
'fr_chair' => Input::get('fr_chair'),
'pr_sectional' => Input::get('pr_sectional'),
'pr_ottoman' => Input::get('pr_ottoman'),
'pr_tile' => Input::get('pr_tile'),
'pr_hardwood' => Input::get('pr_hardwood')
];
$empty = 'No services were selected';
$var = $input['rooms']&& $input['pr_deodorizer']&&
$input['pr_protectant']&& $input['pr_sanitizer']&&
$input['fr_couch']&& $input['fr_chair']&&
$input['pr_sectional']&& $input['pr_ottoman']&&
$input['pr_tiles']&& $input['pr_hardwood'];
if(empty($var)){
return Redirect::to('book/services')->withErrors($empty)->withInput();
}
foreach($input as $services)
{
$service = new Service();
$service->userID = $user->id;
$service->services = $services;
$service->save();
}
return Redirect::to('book/schedule');
}
我试过 !isset() 但我仍然无法让它工作。