To add optgroup in Livewire blade file, you can use the optgroup tag in the select element. Here's an example:
<select wire:model="parent_id">
<option value="">Choose parent category</option>
@foreach($categories as $category)
<optgroup label="{{ $category['name'] }}">
@foreach($category['subCategories'] as $subCategory)
<option value="{{ $subCategory['id'] }}">{{ $subCategory['name'] }}</option>
@endforeach
</optgroup>
@endforeach
</select>
In this example, we are using a nested foreach loop to iterate over the $categories array and its subCategories attribute. We are using the optgroup tag to group the subcategories under their parent category. The label attribute of the optgroup tag is set to the parent category name. The value attribute of the option tag is set to the subcategory ID, and the text between the opening and closing option tags is set to the subcategory name.
