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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化