Auth.user.modulos().fetch()

Hello, how are you?

I’m a PHP programmer I came from laravel but now I’m studying NODE.JS / Adonis and there in laravel you could call functions by the “Auth” example:
Laravel:
Auth :: User-> Pages ()

I tried to do something similar in Adonis but I was unsuccessful did so:
auth.user.modulos () or auth.user.modulos (). fetch ()

and it didn’t work does anyone know if this is possible?

thanks.

Hello!

You need to define relationships first https://adonisjs.com/docs/4.1/relationships#_basic_example

const Model = use('Model')

class User extends Model {
  profile () {
    return this.hasOne('App/Models/Profile')
  }
}

module.exports = User
const Model = use('Model')

class Profile extends Model {
}

module.exports = Profile

And then fetch like this

const user = await User.find(1)
const userProfile = await user.profile().fetch()
// or
const userProfile = await auth.user.profile().fetch()

sorry I forgot to send my MODEM is already like this … in javascript works using:
auth.user.modules (). fetch ()

but I want to loop it in EDGE HTML!

like this:
@each (u in auth.user.modules (). fetch ()) or
@each (u in auth.user.modules ())

but it does not work on the edge

Model:
modulos () {
return this.hasMany(‘App/Models/Modulo’)
}

why this does not working?

@each(u in auth.user.modulos().fetch())

                                    <li class="">

                                        <a href="index.html">

                                            <span class="pcoded-mtext">{{u.name}} <span class="pcoded-badge label label-success">{{u.status}}</span></span>

                                        </a>

                                    </li>

                                @endeach

You cant fetch data in Edge files. You should fetch it in controller and then send data to Edge

1 Like