[英]Laravel passing 0 as value through form and getting null
So I have a simple form with select input which has an option with value of "0" :所以我有一个带有选择输入的简单表单,它有一个值为 "0" 的选项:
<form method="post" action="{{ action('Something@something') }}">
<select name="status">
<option selected value="0">Bla bla bla</option>
</select>
<button type="submit">Press me</button>
</form>
Error occurs, when I select the only option from select input and in controller I get null instead of "0" number (I did check with dd() method).发生错误,当我从选择输入和控制器中选择唯一选项时,我得到空而不是“0”数字(我确实使用 dd() 方法进行了检查)。 Is it possible that this number gets lost in an integrated middleware or somewhere else?这个数字是否有可能在集成中间件或其他地方丢失? Or is this a PHP trick?或者这是一个PHP技巧?
Okay, the answer was that in my Middleware I had this code :好的,答案是在我的中间件中我有这个代码:
public function handle($request, Closure $next)
{
if (!Auth::check()) {
return redirect('/blablabla');
}
foreach ($request->input() as $key => $value) {
if (empty($value)) {
$request->request->set($key, "");
}
}
return $next($request);
}
problem was with empty($value)
.问题在于empty($value)
。 I changed empty()
to !isset()
and everything fixed我将empty()
改为!isset()
并且一切都修复了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.