Show Json data inside a Form Html

1

I have a Grid with the edit button when I click on it it accesses the Controller and brings the data into a Json and "Theoretically" was to return that data in a Modal.

When I type Url .... show / (ID) the Json data appears but I am not able to make this data appear on the Modal Form.

Follow the Code

HTML (Button and Inputs where data was to appear)

<a href="#"  onclick="GetAlunoDetails('{{$valor->id}}')" data-target="#editModal" data-toggle="modal">{{ $valor->nome }}</a>


<input type="text"  class="form-control" id='nometeste'  name="nometeste" value="">

<input type="text"  class="form-control" id='idteste'  name="idteste" value="">

<input type="hidden" id="hidden_user_id">

JS

 function GetAlunoDetails(id) {

    $("#hidden_user_id").val(id);
    $.get("/.../alunos/show/"+id, {

        },
        function (data) {
            // PARSE json data
            var aluno = JSON.parse(data);
            // Assing existing values to the modal popup fields
            $("#nometeste").val(aluno.nome);
            $("#idteste").val(aluno.id);


        }
    );
    // Open modal popup
    $("#editModal").modal("modal");
}

CONTROLLER

public function show($id)
{


//Pegando os valores para preencher a tabela
$aluno= $this->aluno
    ->select('*')
    ->find($id);

return response()->json($aluno);
}
    
asked by anonymous 25.08.2016 / 20:57

1 answer

0

The problem can be in your model query. Assuming you have a model called 'Student'. Instead of $aluno= $this->aluno->select('*')->find($id); make $aluno = Aluno::find($id); .

I hope to help

    
25.08.2016 / 22:37