简体   繁体   中英

Laravel 6 - Registration on submit returns registration form

I'm trying to use the auth build-in in Laravel 6. But when I try to register, the page returns the same register form. When I'm debugging I see that it's going into the validator method in the RegisterController, but not in the create method. Also the password confirmation is not being done client side so if the passwords don't match, it is still just reloading the page.

I really have no idea if I'm doing it the right way, but it looks like the php artisan ui:auth isn't fully installed.

Is it possible that it's not working because I'm using dutch variable names?

RegisterController:

use RegistersUsers;

/**
 * Where to redirect users after registration.
 *
 * @var string
 */
protected $redirectTo = '/';


/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
     $this->middleware('guest');

}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{

    $returnvalue = Validator::make($data, [
        'voornaam' => ['required', 'string', 'max:255'],
        'achternaam' => ['required', 'string', 'max:255'],
        'gezin_id' => ['int'],
        'geboortedatum' => ['required', 'date'],
        'adres' => ['required', 'string', 'max:255'],
        'postcode' => ['required', 'string', 'max:8'],
        'gemeente' => ['required', 'string', 'max:255'],
        'land' => ['required', 'string', 'max:255'],
        'gsm' => ['required', 'string', 'max:12'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        'password' => ['required', 'string', 'min:8', 'confirmed'],
    ]);

    return ($returnvalue);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    dd(request()->all());

    return User::create([
        'voornaam' => $data['voornaam'],
        'achternaam' => $data['achternaam'],
        'geboortedatum' => $data['geboortedatum'],
        'adres' => $data['adres'],
        'postcode' => $data['postcode'],
        'gemeente' => $data['gemeente'],
        'land' => $data['land'],
        'gsm' => $data['gsm'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]);
}

register.blade.php

@section('content')
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">{{ __('Registreer') }}</div>

                    <div class="card-body">
                        <form method="POST" action="{{ route('register') }}">
                            @csrf

                            @if($errors->any())
                                <div class="row collapse">
                                    <ul class="alert-box warning radius">
                                        @foreach($errors->all() as $error)
                                            <li> {{ $error }} </li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif

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

                                <div class="col-md-6">
                                    <input id="voornaam" type="text"
                                           class="form-control @error('voornaam') is-invalid @enderror" name="voornaam"
                                           value="{{ old('voornaam') }}" required autocomplete="voornaam" autofocus>

                                    @error('voornaam')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                            </div>

                            [...]

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

                                <div class="col-md-6">
                                    <input id="password-confirm" type="password" class="form-control"
                                           name="password_confirmation" required autocomplete="new-password">
                                </div>
                            </div>

                            <div class="form-group row mb-0">
                                <div class="col-md-6 offset-md-4">
                                    <button type="submit" class="btn btn-primary">
                                        {{ __('Registreer') }}
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

UPDATE

validator value returns:

Validator {#282 ▼
  #translator: Translator {#280 ▶}
  #container: Application {#2 ▶}
  #presenceVerifier: DatabasePresenceVerifier {#281 ▶}
  #failedRules: []
  #messages: null
  #data: array:12 [▶]
  #initialRules: array:11 [▶]
  #rules: array:11 [▶]
  #currentRule: null
  #implicitAttributes: []
  #distinctValues: []
  #after: []
  +customMessages: []
  +fallbackMessages: []
  +customAttributes: []
  +customValues: []
  +extensions: []
  +replacers: []
  #fileRules: array:9 [▶]
  #implicitRules: array:10 [▶]
  #dependentRules: array:18 [▶]
  #sizeRules: array:8 [▶]
  #numericRules: array:2 [▶]
}

So, looks like no validation errors?

I found out it was just a stupid mistake.

I used all dutch variables, so the password-confirmation wasn't possible anymore by validator. The only thing I still don't understand is why I didn't get any error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM