добавить эти функции в вашу модель
public function children()
{
return $this->hasMany(Category::class, 'parent_id', 'id');
}
public function parent()
{
return $this->belongsTo(Category::class, 'parent_id', 'id');
}
Тогда по вашему мнению:
@foreach ($categories as $category)
@if($category->parent_id == 0)
@include('categories.view', $category)
@endif
@endforeach
А это содержимое Categories.view.blade file
<li id="{{$category->id}}" data-jstree='{"icon":"fa {{$category->icon}}"}'>
<a href="#">{{ $category->name }}</a>
@if ($category->children()->count() > 0)
<ul>
@foreach($category->children as $category)
@include('categories.view', $category)
@endforeach
</ul>
@endif
</li>