2017-06-13 21 views
1

新しいLaravelプロジェクトを作成しました。私は標準php artisan make:auth を使用し、それは必要なファイルと接続を生成しました。私はphpMyAdminでテーブルを作成し、2つを.envファイルに接続しました。私は接続と移行をチェックし、すべてうまく動作します。新しいLaravelプロジェクトでユーザー登録を修正するにはどうすればよいですか?

問題は、私は新しいユーザーを作成し、すべてのレジスタのデータを入力したい場合、フィールドfirst_namelast_nameが明らかに読み取ることができないと私はを言ってエラーが出るということである「最初の名前フィールドが必要です。」姓が同じです。パスワードや電子メールにエラーはありません。

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> 

および移行:私はフォーラムやLaravelのマニュアルを確認したがcouldn

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'); 
    } 
} 

まず、ここRegisterControllerです間違いを見つける。

答えて

3

問題はここにある:

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

代わりのname="first_name"first_name="first_name"があります。適切にしてからもう一度やり直してください。 last_name="last_name"でも同じです。

説明:サーバー側で

、要素の値は、要素のname属性を使用してフェッチされます。しかし、あなたのケースでname属性が存在しないため、検証が失敗し、それが表示されています最初のフィールドはと同じですlast_nameのため

関連する問題