{{-- Thanks to Erwan Pianezza - https://github.com/breizhwave--}} {{-- This field assumes you have a nested set Eloquent model, using: --}} {{-- 1. children() as a properly defined relationship --}} {{-- 2. depth, lft attributes --}} @php $current_value = old($field['name']) ? old($field['name']) : (isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '' )); if (!function_exists('echoSelect2NestedEntry')) { function echoSelect2NestedEntry($entry, $field, $current_value) { if ($current_value == $entry->getKey()) { $selected = ' selected '; } else { $selected = ''; } echo ""; } } if (!function_exists('echoSelect2NestedChildren')) { function echoSelect2NestedChildren($entity, $field, $current_value) { foreach ($entity->children()->get() as $entry) { echoSelect2NestedEntry($entry, $field, $current_value); echoSelect2NestedChildren($entry, $field, $current_value); } } } @endphp