【问题标题】:Laravel: Condition in select dropdownLaravel:选择下拉列表中的条件
【发布时间】:2015-04-18 16:24:30
【问题描述】:

我想从我的视图中获取我的选择下拉列表的值到我的控制器

有什么办法可以得到这个吗? :(

这是我的下拉视图

{{ Form::select('status', ['All', 'Absent', 'Late', 'Others']) }}

这里是我想要调整我选择的值的地方

    public function filterSummaryStudent()
    {
        if(Input::has('status') == 'All')
        {

      (other codes here)
         }

当我打电话给这个时,我得到了一个空白页。请帮忙。谢谢!

【问题讨论】:

  • 你只是想检索控制器中的下拉值?

标签: php laravel laravel-4 eloquent laravel-5


【解决方案1】:

如果要将值检查为字符串,则必须将选择下拉列表的值指定为关联数组。现在,您的选择下拉代码中的值是使用数组的数字索引定义的。当您检查 Input::has('status') == 'All' 时,laravel 当然会返回 false。

您的代码

{{ 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>

如果你像上面的代码那样写,你可以像这样检查选择下拉菜单。

if(Input::has('status') == 'All') {
    // Your code
}

【讨论】:

    猜你喜欢
    • 2013-07-29
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 2011-12-06
    • 2016-08-18
    相关资源
    最近更新 更多