I have a MySQL table as
+--------------------+--------------------+--------------------+
| Id | parent_id | title |
+--------------------+--------------------+--------------------+
| 1 | 0 | Student Management |
|--------------------|--------------------|--------------------|
| 2 | 0 | Staff Management |
|--------------------|--------------------|--------------------|
| 3 | 1 | Add Student |
|--------------------|--------------------|--------------------|
| 4 | 1 | View Students |
|--------------------|--------------------|--------------------|
| 5 | 2 | Add Staff |
|--------------------|--------------------|--------------------|
| 6 | 2 | View Staff |
|--------------------|--------------------|--------------------|
| 7 | 4 | Delete |
|--------------------|--------------------|--------------------|
| 8 | 5 | Copy |
+--------------------+--------------------+--------------------+
I want to rise higher, in my opinion, recursively.
Desired Conclusion
+-------------------------------+------------------------------+
| Student Mangement | Staff Management |
| Add Student | Add Staff |
| View Student | Copy |
| Delete | View Staff |
+-------------------------------+------------------------------+
I want to get above the MySQL table as the structure that I defined above
My method of getting like
public function get()
{
$categories = Categories::where('parent_id', '=', 0)->get();
$permission = Categories::pluck('title','id')->all();
return view('create-role')->with(compact('categories'));
}
With the above method, I get the parents in the view as
@foreach($categories as $category)
<li>
{{ $category->title }}
</li>
@endforeach
Output as
Student management
Personnel Management
Please help how can I get the above structure recursively.
source
share