Using Factory in Controller

I’m trying to use Factory inside a controller for testing only. Is this not possible?

The error I’m getting: “Cannot find module ‘Factory’”

I’m ultimately trying to create dummy data inside an instance, without using the Ace command. Any thoughts?



Can you share some code?


// factories.js
const Factory = use('Factory')
const Hash = use('Hash')
Factory.blueprint('App/Models/User', async (faker) => {
  return {
    username: faker.username(),
    password: await Hash.make(faker.password())

// user.spec.js
const Factory = use('Factory')
const user = await Factory.model('App/Models/User').create()
1 Like

/// ApiController.js

const Factory = use("Factory");
class ApiController {
  async getCities({request, response}) {
    const user = await Factory.model('App/Models/User').make()

    return null

i not read ‘inside a controller’ :sweat_smile:

this case, i dont know as use Factory inside controller. sorry bro