du3979 2018-01-23 05:25
浏览 19
已采纳

错误表单选择,Laravel

So I have this dropdown select for floor levels in my create form its working fine but the edit form I want to set the dropdown selection to the floor that's been selected in the create form instead of having an empty drop-down select so what I did is this

 <div class="form-group">
                {!! Form::label('Office Floor') !!}
                {{Form::select('floor', $office->floor,
                [ ''=>'',
                  'Basement' => 'Basement',
                  '1st Floor' => '1st Floor',
                  '2nd Floor' => '2nd Floor',
                  '3rd Floor' => '3rd Floor',
                  '4th Floor' => '4th Floor',

                ], null,['class' => 'form-control'])}}

I used to have input fields before and "$office->floor" is working but when I try that it has this error

Type error: Argument 4 passed to Collective\Html\FormBuilder::select() must be of the type array, null given, called in C:\xampp\htdocs\Eguide\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 221 (View: C:\xampp\htdocs\Eguideesources\views\editoffice.blade.php)

createoffice.blade.php

{!! Form::open(array('route' => ['createoffice', $id], 'class' => 'form')) !!}
<div class="container">

            <div class="form-group">
                {!! Form::label('Office Name') !!}
                {!! Form::text('officename', null,        array('required',
                          'class'=>'form-control',
                          'placeholder'=>'Office Name')) !!}
            </div>

            <div class="form-group">
                {!! Form::label('Office Floor') !!}
                {{Form::select('floor',
                [ ''=>'',
                  'Basement' => 'Basement',
                  '1st Floor' => '1st Floor',
                  '2nd Floor' => '2nd Floor',
                  '3rd Floor' => '3rd Floor',
                  '4th Floor' => '4th Floor',

                ], null,['class' => 'form-control'])}}


                <!--{!! Form::text('floor', null,        array('required',
                          'class'=>'form-control',
                          'placeholder'=>'Office Floor')) !!} -->
            </div>

<div class="form-group">

    {!! Form::submit('Create Office',
      array('class'=>'btn btn-primary')) !!}

  <a href="{{ url('building/' . $id) }}"  class="btn btn-info">
   <span class="glyphicon glyphicon-arrow-left"></span>  Back
 </a>

</div>
{!! Form::close() !!}

@endsection
  • 写回答

2条回答 默认 最新

  • douxi2011 2018-01-23 05:30
    关注

    Remove $office->floor and it will work fine

    {{Form::select('floor',
                [ ''=>'',
                  'Basement' => 'Basement',
                  '1st Floor' => '1st Floor',
                  '2nd Floor' => '2nd Floor',
                  '3rd Floor' => '3rd Floor',
                  '4th Floor' => '4th Floor',
    
                ], null,['class' => 'form-control'])}}
    

    And if you want the field to be selected by $office->floor, then change null to $office->floor like-

    {{Form::select('floor',
                [ ''=>'',
                  'Basement' => 'Basement',
                  '1st Floor' => '1st Floor',
                  '2nd Floor' => '2nd Floor',
                  '3rd Floor' => '3rd Floor',
                  '4th Floor' => '4th Floor',
    
                ], $office->floor,['class' => 'form-control'])}}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)