Laravel:select 下拉列表中的条件
Laravel: Condition in select dropdown
我想从我的视图中获取我的 Select 下拉列表的值到我的控制器
有什么办法可以得到这个吗? :(
这是我的下拉视图
{{ Form::select('status', ['All', 'Absent', 'Late', 'Others']) }}
这里是我要调节我选择的值的地方
public function filterSummaryStudent()
{
if(Input::has('status') == 'All')
{
(other codes here)
}
当我调用这个时,我得到了一个空白页面。请帮忙。谢谢!
如果要检查字符串形式的值,则必须将 select 下拉列表的值指定为关联数组。现在,您的 select 下拉代码的值是使用数组的数字索引定义的。当您检查 Input::has('status') == 'All' 时,当然 laravel 将 return 为假。
您的代码
{{ Form::select('status', ['All', 'Absent', 'Late', 'Others']) }}
HTML输出
<select name="status">
<option value="0">All</option>
<option value="1">Absent</option>
<option value="2">Late</option>
<option value="3">Others</option>
</select>
正确的代码
{!! Form::select('status', ['All' => 'All', 'Absent' => 'Absent', 'Late' => 'Late', 'Others' => 'Others']) !!}
HTML输出
<select name="status">
<option value="all">All</option>
<option value="absent">Absent</option>
<option value="late">Late</option>
<option value="others">Others</option>
</select>
如果你像上面的代码那样写,你可以像这样检查 select 下拉列表。
if(Input::has('status') == 'All') {
// Your code
}
我想从我的视图中获取我的 Select 下拉列表的值到我的控制器
有什么办法可以得到这个吗? :(
这是我的下拉视图
{{ Form::select('status', ['All', 'Absent', 'Late', 'Others']) }}
这里是我要调节我选择的值的地方
public function filterSummaryStudent()
{
if(Input::has('status') == 'All')
{
(other codes here)
}
当我调用这个时,我得到了一个空白页面。请帮忙。谢谢!
如果要检查字符串形式的值,则必须将 select 下拉列表的值指定为关联数组。现在,您的 select 下拉代码的值是使用数组的数字索引定义的。当您检查 Input::has('status') == 'All' 时,当然 laravel 将 return 为假。
您的代码
{{ Form::select('status', ['All', 'Absent', 'Late', 'Others']) }}
HTML输出
<select name="status">
<option value="0">All</option>
<option value="1">Absent</option>
<option value="2">Late</option>
<option value="3">Others</option>
</select>
正确的代码
{!! Form::select('status', ['All' => 'All', 'Absent' => 'Absent', 'Late' => 'Late', 'Others' => 'Others']) !!}
HTML输出
<select name="status">
<option value="all">All</option>
<option value="absent">Absent</option>
<option value="late">Late</option>
<option value="others">Others</option>
</select>
如果你像上面的代码那样写,你可以像这样检查 select 下拉列表。
if(Input::has('status') == 'All') {
// Your code
}