Laravel在刀片中循环通过阵列

时间:2016-01-09 20:56:31

标签: php arrays laravel-5.1 laravel-blade

我有以下数组:

$days = [
    ['dow' => 1, 'day' => 'Monday'],
    ['dow' => 2, 'day' => 'Tuesday'],
    ['dow' => 3, 'day' => 'Wednesday'],
    ['dow' => 4, 'day' => 'Thursday'],
    ['dow' => 5, 'day' => 'Friday'],
    ['dow' => 6, 'day' => 'Saturday'],
    ['dow' => 7, 'day' => 'Sunday'],
];

我试图在我的刀片模板中循环播放,如下所示:

 @foreach ($days as $day)
       <label>{{$day['day']}}</label>
       {!! Form::text('day_of_wk[$day['dow']].start_time', null, ['class' => 'form-control'])!!}
  @endforeach

但我收到错误:syntax error, unexpected 'dow' (T_STRING)

如何在day_of_wk []输入数组中添加$day['dow']值?

1 个答案:

答案 0 :(得分:3)

        $(document).ready(function() {
         <!--The parent dropdown-->
            $("#id_REGION").change(function() {
                var el = $(this);
                var select = document.getElementById("id_CITY");
                $("#id_CITY").val([]);
                select.length = 0;
                $("#id_CITY").append("<option value=\"\" selected=\"selected\">---------</option>");
            <!--Clears the field for new entry-->

                var reg = [{% for item in a %}"{{ item.Region_Designated_id }}"{% if not forloop.last %},{% endif %}{% endfor %}];
                var city_name = [{% for item in a %}"{{ item.CITY }}"{% if not forloop.last %},{% endif %}{% endfor %}];

               <!--filling the dropdown-->
                for(var i = 0; i<reg.length; i++){

                <!--Filtering the entries-->
                    if(el.val() == reg[i]){
                        $("#id_CITY").append("<option id = "+ reg[i] +" value = \"" + city_name[i] + "\">" + city_name[i] + "</option>");
                    }

                }
            });
        });

  @foreach ($days as $day)
       <label>{{$day['day']}}</label>
       {!! Form::text('day_of_wk['.$day['dow'].'].start_time', null, ['class' => 'form-control'])!!}
  @endforeach