Form value does not return in the Collective

Asked

Viewed 49 times

2

The form in the edção part, does not show the value coming from the database. All other form fields are returning the value taken in the database. See 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 parameter of Form:() o NULL, is where the database data comes back. More is not coming back. What will pass this happening.

1 answer

1


You have enough problems doing it like this, you better create a array in his controller and move on to the 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);
}

Observing: remembering that to carry this Form::select needs to be a array key and value, as demonstrated 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 position itself on the record when you pass $id_departamento to the View.

Just ratifying as it should pass:

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

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

References

  • 1

    I solved otherwise, but I didn’t know I had a way to do this way Very good. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.