Skip to content
Advertisement

How to display departments as nodes in Laravel

I have a table i db ‘departments’ .I want it do display it with jstree.I have a parent_id,the root node that is 0 and another that is 1 .I have problems in displaying them in a parent and child relationship..Here is my code and what i have tried but the problem is that it is displaying like this:

JavaScript

and i want it like this

JavaScript

JavaScript

enter image description here

Advertisement

Answer

It sounds like you might want to create a self referential relationship, using laravel’s ORM. Check out the one to one relationship.

Your finished code may look something like this:

Department.php

JavaScript

department.blade.php

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement