2017-06-13 2 views
1

Ich habe ein neues Laravel-Projekt erstellt. Ich benutzte den Standard php artisan make:auth und das erzeugte die erforderlichen Dateien und Verbindungen. Ich erstellte die Tabelle in phpMyAdmin und verband die beiden in der .env Datei. Ich habe Verbindungen und Migrationen überprüft und alles funktioniert gut.Wie kann ich die Benutzerregistrierung in meinem neuen Laravel-Projekt beheben?

Das Problem ist, dass, wenn ich einen neuen Benutzer erstellen möchten, und geben Sie alle Registerdaten, die Felder first_name und last_name offenbar nicht gelesen werden kann, und ich erhalte eine Fehlermeldung, „Der erste Name Feld erforderlich ist.“ Gleiches für den Nachnamen. Kein Fehler bei Passwort oder E-Mail.

Zuerst ist hier die RegisterController:

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

protected function create(array $data) 
{ 
    return User::create([ 
     'first_name' => $data['first_name'], 
     'last_name' => $data['last_name'], 
     'email' => $data['email'], 
     'password' => bcrypt($data['password']), 
    ]); 
} 

register.blade.php:

<form class="form-horizontal" role="form" method="POST" action="{{ route('register') }}"> 
    {{ csrf_field() }} 

    <div class="form-group{{ $errors->has('first_name') ? ' has-error' : '' }}"> 
     <label for="first_name" class="col-md-4 control-label">First Name</label> 

     <div class="col-md-6"> 
      <input id="first_name" type="text" class="form-control" first_name="first_name" value="{{ old('first_name') }}" required autofocus> 

      @if ($errors->has('first_name')) 
       <span class="help-block"> 
        <strong>{{ $errors->first('first_name') }}</strong> 
       </span> 
      @endif 
     </div> 
    </div> 

    <div class="form-group{{ $errors->has('last_name') ? ' has-error' : '' }}"> 
     <label for="last_name" class="col-md-4 control-label">Last Name</label> 

     <div class="col-md-6"> 
      <input id="last_name" type="text" class="form-control" last_name="last_name" value="{{ old('last_name') }}" required autofocus> 

      @if ($errors->has('last_name')) 
       <span class="help-block"> 
        <strong>{{ $errors->first('last_name') }}</strong> 
       </span> 
      @endif 
     </div> 
    </div> 

und Migrationen:

class CreateUsersTable extends Migration 
{ 
    public function up() 
    { 
     Schema::create('users', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('first_name', 20); 
      $table->string('last_name', 30); 
      $table->string('email')->unique(); 
      $table->string('password', 30); 
      $table->rememberToken(); 
      $table->timestamps(); 
     }); 
    } 

    public function down() 
    { 
     Schema::dropIfExists('users'); 
    } 
} 

Ich habe Foren und die Laravel Dokumentation aber couldn‘ t einen Fehler finden.

Antwort

3

Die Frage ist hier:

<input id="first_name" type="text" class="form-control" first_name="first_name" value="{{ old('first_name') }}" required autofocus> 

hier statt name="first_name" ist first_name="first_name" dort. Machen Sie es richtig und versuchen Sie es erneut. Das Gleiche gilt für last_name="last_name" auch.

Erläuterung:

Auf der Serverseite, Elementwert abgerufen wird das name Attribut des Elements verwendet wird. Aber in Ihrem Fall name Attribut fehlt, was die Validierung schlägt fehl und es zeigt Das erste Name Feld ist erforderlich und das gleiche für last_name

Verwandte Themen