I want to display indented subcategories in the html option tag. I created a recursive iteration in a separate file that I import in a foreach statement. With the first subcategories, I get a prefix of one space and when it starts to load deeper levels, the indent is the same and should be increased by one more.
How can i increase the indented (prefix) for each level that is deeper?
I expect it to be like this:
Root
Child
Sub child 1
Sub child 2
Sub sub child
My real exmple when code is excuted is like this:
Root
Child
Sub child 1
Sub child 2
Sub sub child
(no prefix spaces in Sub childrens)
Controller
public function create()
{
$categories = BlogCategory::where('parent_id', '')->get();
return view('ecommerce::admin.post.create', [
'categories' => $categories
]);
}
form.blade.php
<select name="public" id="page_category_field" class="custom-select {{ $errors->has('status') ? 'is-invalid' : ''}}">
@foreach($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
@if(count($category->childrens) > 0)
@include('ecommerce::admin.post.loop.nested_category_html_select', ['childrens' => $category->childrens])
@endif
@endforeach
</select>
nested_category_html_select.blade.php
@foreach($childrens as $child)
<option value="{{ $child->id }}"> {{ $child->name }}</option>
@if(count($child->childrens) > 0)
@include('ecommerce::admin.post.loop.nested_category_html_select', ['childrens' => $child->childrens])
@endif
@endforeach
Here is problem in  :
<option value="{{ $child->id }}"> {{ $child->name }}</option>
How to add more spaces for each new level?