Can i call controller function from edge view?

Hi, i want create a function to check permission was assign to role in my controller and return the 'checked="checked"' and call the function from edge view.

in my controller

checkPermisisonChecked(role, permission) {

}

in my edge view
{{ checkPermisisonChecked(role, permisison) }}

Controller doesn’t work like that. Use start/hooks.js instead for example :

const { hooks } = require("@adonisjs/ignitor");

hooks.after.providersBooted(() => {

	const View = use("View");

    View.global("nl2br", function(str) {
		return (str + "").replace(
			/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,
			"$1" + "<br />" + "$2"
		);
	});
});

Call it in edge :

 {{ nl2br(content) }}
1 Like

tanks for the solution