Create field Select in the default form of laravel for user registration

0

I am trying to modify the RegisterController by default of laravel and one of the fields of the form that I am going to use is of type select.

but I can not send the data array to the view to show the drop-down menu of the select.

this is my html code:

<div class="form-group row">
                            <label for="neighborhood"
                                   class="col-md-4 col-form-label text-md-right">{{ __('barrio') }}</label>

                            <div class="col-md-6">
                                <select id="neighborhood" name="neighborhood" class="form-control" value="{{ old('neighborhood') }}">
                                    <option selected>Seleccione un Barrio</option>
                                    @foreach ($neighborhoods as $barrio)
                                        <option value="{{ $barrio->id }}">{{$barrio->name}}</option>
                                    @endforeach
                                </select>

                                @if ($errors->has('neighborhood'))
                                    <span class="invalid-feedback" role="alert">
                                    <strong>{{ $errors->first('neighborhood') }}</strong>
                                </span>
                                @endif
                            </div>
                        </div>

Then in the controller part I have this.

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    $neighborhoods = Neighborhood::pluck('id','name');
    //return view('auth.register',compact('neighborhoods') );

    Return User::create([
        'name' => $data['name'],
        'last_name' => $data['last_name'],
        'document' => $data['document'],
        'phone' => $data['phone'],
        'cel_phone' => $data['cel_phone'],
        'doc_id' => $data['doc_id'],
        'neighborhood_id' => $data['neighborhood_id'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]);
}

and this is the error that is presenting me

  

Undefined variable: neighborhoods (View: /var/www/html/test/resources/views/auth/register.blade.php)

    
asked by Jaime Alexander Gaona Quiroga 15.10.2018 в 01:45
source

0 answers