I am trying to validate a dropdown list. The items of the list is taking from database and is shown below.
<select class="form-control" name="clstechid">
<option value="0">Select</option>
@foreach($persons as $person)
@if($person->ttype == 1)
<option value="{{$person->id}}">{{$person->tname}}</option>
@endif
@endforeach
</select>
I want to validate this dropdown menu. The selected item should not be 'Select' option. How will I validate?? Can anyone help??
Try to set the value attribute to a null value:
<option value="">Select</option>
Change Val from 0 to
<option value="">-- Select --</option>
Theres a really nice way to do this in Laravel using the lists function on a Collection.
Controller
$select = ['' => 'Please Select'] + $persons->where('ttype', 1)->lists('tname', 'id');
return view('my.view', compact('select'));
View
{!! Form::select('clstechid', $select) !!}