can anyone suggest me how can I use a custom class for writing all helper methods so that the app doesn't repeat same code again and again in different controllers? How can I share codes between controllers? Thank you
Ok I solved it. In case someone else is trying to solve it, here is how I solved
In app
folder I created a folder named Common
. Inside this folder I have a index.js
. (App/Common/index.js
) in this file I have
'use strict';
module.exports = class Help {
display() {
console.log('is it ok?')
}
}
Now in my controllers I need to use it like this
var Help = use('App/Common')
In order to call the display method
I need to call just like a normal OOP call
var obj = new Help();
obj.display();
That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With