Hi guys in my laravel project I have some javascript helpers function that utilizes jquery I want to extract to a separate place that all parts of the application can use. These are the function stored in helper.js :
// bootbox function to delete records
// it utitlizes the bootbox library
window.bootbox_delete = function (message, route, row) {
// body...
bootbox.dialog({
message: message,
title: "<i class='glyphicon glyphicon-trash'></i> Delete !",
buttons: {
success: {
label: "No",
className: "btn-success",
callback: function callback() {
$('.bootbox').modal('hide');
}
},
danger: {
label: "Delete!",
className: "btn-danger",
callback: function callback() {
$.ajax({
type: 'DELETE',
url: route
}).done(function (data) {
bootbox.alert('<b>' + data.name + '</b> successfully deleted');
//removing the row that have been deleted
jQuery(row).fadeOut('slow');
}).fail(function () {
bootbox.alert('Something Went Wrong .... Please contact administrator');
});
}
}
}
});
}
// function that displays notification
window.notify = function(message) {
// body...
$.notify({
icon: 'fa fa-check',
message: message
}, {
type: 'success',
timer: 4000,
offset: 20,
spacing: 10,
z_index: 1031,
delay: 5000,
placement: {
from: "top",
align: "right"
},
animate: {
enter: 'animated fadeInDown',
exit: 'animated fadeOutUp'
}
});
}
What I have done is that I added helper.js to resources/assets/js and compile to public/js/app.js with npm run dev but whenever I tried to see if things are working I get these errors:
notify is not defined
bootbox_delete is not defined
helper.jsin yourapp.jsfile? I.e. are you requiringhelper.jsfile in yourapp.jsfile or are you compiling it in yourwekpack.mix.jsfile? Either can you show the code for this.