TeamPlar Jarj
TeamPlar Jarj

Reputation: 121

Error form select, 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\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

Upvotes: 2

Views: 1560

Answers (2)

bharat
bharat

Reputation: 1776

You can try this:

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

Upvotes: 1

Sohel0415
Sohel0415

Reputation: 9853

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

Upvotes: 3

Related Questions