I want to create a select field with optgroups
$spec = DB::table('agentspec')->orderBy('category', 'desc')->get();
The table has three columns
category, spec, agentdesc
The optgroup label is "category" with "spec" as the select value
This is what I've tried getting error Trying to get property of non-object
@foreach($spec as $spec)
@if ($spec->category == 'Agent')
<optgroup label="Agent">
@foreach($spec as $spec)
<option value="{{ $spec->spec}}">{{ $spec->spec }}{{ $spec->agentdesc }}</option>
@endforeach
</optgroup>
@endif
@endforeach