Laravel - Does not take the table column

0

I'm in a dilemma in Laravel that I can not solve, and I've tried a lot of things and now I've stuck here: What I want is to give% of a column value of my table by echo .

Code no input :

public function retorna_curso()
{
    $id_curso = Input::get('id_curso');
    $cursos = DB::table('cursos')->get();
    $select = DB::table('cursos')->where('id_curso', '=', $id_curso)->get();
    return view('editar.update_curso')
            ->with('select', $select)
            ->with('cursos', $cursos);
}

Code in html :

<form action="/updt_curso" method="post"> 
 <div class="form-group col-md-12">
    <?php              
       if(isset($select))
       {
            echo' <div class="form-group col-md-12">
            <label for="edt_nome">Editar nome do curso:</label>
                <input type="text" 
                       class="form-control" 
                       name="input_nomeCurso" 
                       value="'.$select['nome'].'" 
                       id="nomeCurso">';                    
            echo'
            </div>
            <div class="form-group col-md-4">
                <input type="submit" 
                       value="Atualizar" 
                       class="form-control btn btn-primary">
            </div>';
        }                   
    ?>
 </div> 
</form>

It enters Controller , but gives an exception saying that the View property does not exist in if nome that it sends back to page.

  • What could I do to solve this problem?
  • What's missing to work?
asked by anonymous 15.11.2016 / 22:04

1 answer

1

Use only with with the array you want to send to the view:

...
return view('editar.update_curso')->with(['select' => $select, 'cursos' => $cursos]);

Remember that $select is an array of objects, where each row is an object, you have to select which index (row) you want, which in this case is the first one because id suppose to be unique in table, change your if by:

if(isset($select[0])) { // verificar se há alguma linha retornada

And no value stays:

    ... value="' .$select[0]->nome. '" ...
    
15.11.2016 / 22:19