Form Value does not return in Collective laravel

2

The form in the edit part does not display the value coming from the database. All other form fields are returning the value I get in the database. Here's how I'm doing:

<div class="col-md-3">
      {!! Form::label('departamento','Departamento', array('class'    =>  'control-label')) !!}
      {!! Form::select('departamento',[
            'null' =>  'Escolha uma Opção',
            'jeans'             =>  'Jeans', 'senhores e senhoras'      =>   'Senhores e Senhoras',
            'grupo de Louvor'   =>  'Grupo de Louvor', 'kids'           =>  'Kids',  
            'geral'             =>  'Geral',
            ],null,['class'  => 'form-control']) !!} 
</div> 

As far as I know, the option passed in the Form :: select () parameter to NULL, is where the database data comes back. More is not coming back. What will happen is happening.

    
asked by anonymous 18.08.2017 / 23:33

1 answer

1

You have a lot of trouble doing so, it's best to create a array in your controller and move to View example :

public function edit($id)
{
    $departamentos[''] = 'Escolha uma Opção';
    $departamentos['jeans'] = 'Jeans';
    $departamentos['grupo de Louvor'] = 'Grupo de Louvor';
    //e assim por diante

    return view("nome da view")
            ->with('departamentos', $departamentos)
            ->with('id_departamento', id_departamento);
}

Note remembering that to load this Form::select must be a array key and value, as shown in function edit

Look at the code reduction:

<div class="col-md-3">
 {!! Form::label('departamento','Departamento', array('class'=>  'control-label')) !!}
 {!! Form::select('departamento', $departamentos, $id_departamento,
                ['class'=>'form-control']) 
      !!} 
</div> 

The select will only be placed in the registry when you pass $id_departamento to View .

Just ratifying how to pass:

  

echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');

  • the first parameter is the name of select
  • the second is% w / key and value
  • The third parameter is responsible for positioning array .

References

19.08.2017 / 00:00