Laravel:选择下拉列表中的条件

Laravel:选择下拉列表中的条件

问题描述:

I want to get the value of my Select Dropdown list from my view to my controller

Is there any way i can get this? :(

Here's my dropdown view

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

Here's where i want to condition my selected value

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

      (other codes here)
         }

I've been getting a blank page when i call this.. Please help. Thank you!

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

有什么方法可以得到这个吗? :( p>

这是我的下拉视图 strong> p>

  {{Form :: select('status',[  '全部','缺席','迟到','其他'])}} 
  code>  pre> 
 
 

这是我想要调整所选值的地方 strong> p>

  public function filterSummaryStudent()
 {
 if if(Input :: has('status')=='All')
 {
 
  (这里的其他代码)
} 
  code>  pre> 
 
 

我打电话给我的时候一直是空白的页面..请帮助。谢谢! p> \ n div>

You must specify the value of select dropdown as associative arrays if you want to check the value as a string. Right now your select dropdown code the value is define using numeric index of the array. When you check the Input::has('status') == 'All', of course laravel will return false.

Your code

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

HTML Output

<select name="status">
    <option value="0">All</option>
    <option value="1">Absent</option>
    <option value="2">Late</option>
    <option value="3">Others</option>
</select>

Correct code

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

HTML Output

<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 you write like the above code you can check the select dropdown like this.

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