错误表单选择,Laravel

时间:2018-01-23 05:25:52

标签: php laravel

所以我在我的创建表单中选择了楼层级别的下拉列表它工作得很好但编辑表单我想将下拉列表选项设置为在创建表单中选择的楼层而不是有一个空的下拉列表选择所以我做的是这个

 <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'])}}

我之前有输入字段,“$ office-&gt; floor”正在运行,但是当我尝试它有这个错误时

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\Eguide\resources\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 个答案:

答案 0 :(得分:3)

删除$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'])}}

如果您希望$office->floor选择字段,请将null更改为$office->floor,如 -

{{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 :(得分:1)

你可以试试这个:

{!! Form::label('Office Floor') !!}
{{Form::select('floor',
[ ''=>'select floor',
    'Basement' => 'Basement',
    '1st Floor' => '1st Floor',
    '2nd Floor' => '2nd Floor',
    '3rd Floor' => '3rd Floor',
    '4th Floor' => '4th Floor',

], '1st Floor',['class' => 'form-control'])}}