DEV Community

Chamara Abeysekara
Chamara Abeysekara

Posted on

LaraCRUDJS

So for the post, I thought I write about something that I developed a few months back. This a JavaScript library I have written to manage CRUD functions.

You can find it no GitHub https://github.com/chamra/laraCRUDJS

Once you downloaded the zip you can place laraCRUD.js file in your assets folder and reference it in your app.balde.php file.

<script src="{{ assets('js/laraCRUD.js') }}"></script>

after that, it's all a matter of time you create an object from CRUD class

const crud = new CRUD()

you can override all defaults from the constuctor. default is,

{
//form element id
this.form = "formData";
//modal id that include the form
this.modal = "#formModal";
//form submit buttom id
this.submitButton = "#btnSubmit";
//propertie for datatables
this.datatables = "";
//resource url
this.url = "";
//unable page refresh afer a form a submit
this.refreshPage = false;
//current status of the form to be update or create
this.update = false;
//csrf token
this.token = document.head.querySelector('meta[name="csrf-token"]');
//selected items auto increment id
this.id = 0;
}

calling the method initCRUDFunctions() on crud will in initiate basic crud function you need for the instance.

crud.initCRUDFunctions()

for example - https://github.com/chamra/laraCRUDJS/blob/master/example/main.js

Help is always welcome, so fork me ✌!

Top comments (0)