Pass database data to a View in Adonisjs

Asked

Viewed 51 times

0

I am searching for a specific data in the database to return its values in a view (Edgetemplate)

But in the view shows how Undefined

My route

Route.get('/atendimentos/:id_atendimento', 'AtendimentoController.show')

Controller Code

 async show ({ params, request, response, view }) {
    const atendimento = await Atendimento.find(params.id_atendimento)

    return view.render('atendimento', {
      atendimento: atendimento
    })

  }

Code of the View

@layout('layout.app')

@section('content')




  {{atendimento.nome_cliente}}



@endsection

There’s something I forgot?

  • in the controller you are passing the variable atendimento have tried atendimento.nome_cliente ?

1 answer

0


You need to convert the result into JSON object like this:

async show ({ params, request, response, view }) { const atendimento = await Atendimento.find(params.id_atendimento) return view.render('atendimento', { atendimento: atendimento.toJSON() }) }

Browser other questions tagged

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