I am creating a registration form in Laravel 5.3, where one of the fields is a "group" that searches in a database. The groups are available and displayed by a select
. The problem is that I could not save, because I think I'm not receiving the value
of select
.
This is my select code:
<div class="form-group{{ $errors->has('id_group') ? ' has-error' : '' }}">
<label for="id_group" class="col-md-4 control-label">Grupos</label>
<div class="col-md-6">
<select class="form-control" name="id_group" >
@foreach($groups as $group)
<option value="{{$group->id}}">{{$group->name}}</option>
@endforeach
</select>
@if ($errors->has('id_group'))
<span class="help-block">
<strong>{{ $errors->first('id_group') }}</strong>
</span>
@endif
</div>
</div>
This is the function where I validated the form data:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:testauths',
'password' => 'required|min:6|confirmed',
'group_id' => 'required|max:255|confirmed',
]);
}
This is my function create
where I save the data:
protected function create(array $data)
{
return Testauth::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'group_id' => $data['group_id'],
]);
}
When sending the form, despite having selected the value of the select, the validation method tells me that nothing has been selected.
Making a dd ($ data) of the validate function shows that the "Group" field is sent empty.