2017-02-17 7 views
2

私は、モーダルウィンドウを使用していくつかの新しいフィールドを追加して、laravelのデフォルト認証システムを変更しようとしています。 だから、私はこのようになります新しいユーザーを登録するには、モーダルウィンドウを持っている: Laravel既定のAuth with Modular

<!-- Modal Register area --> 
<div class="modal fade" id="registerModal" tabindex="-1" role="dialog" aria-labelledby="myRegisterLabel" aria-hidden="true"> 
    <div class="modal-dialog" role="document"> 
    <div class="modal-content"> 
     <form id="formRegister" class="login-form" action="{{ route('register') }}" method="POST"> 

     {{ csrf_field() }} 

     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
      <span aria-hidden="true">&times;</span> 
      </button> 
      <h4 class="modal-title" id="myRegisterLabel">Sign Up</h4> 
     </div> 
     <div class="modal-body"> 
      <div class="form-group"> 
      <label>First Name:</label> 
      <input type="text" name="first_name" placeholder="first name..." value="{{ old('first_name') }}" required autofocus> 
      </div> 
      <div class="form-group"> 
      <label>Last Name:</label> 
      <input type="text" name="last_name" placeholder="last name..." value="{{ old('last_name') }}" required autofocus> 
      </div> 
      <div class="form-group"> 
      <label>Email:</label> 
      <input type="email" name="email" placeholder="email..." value="{{ old('email') }}" required> 
      </div> 
      <div class="form-group"> 
      <label>Password:</label> 
      <input type="password" name="password" required> 
      </div> 
      <div class="form-group"> 
      <label>Password Confirmation:</label> 
      <input type="password" name="password_confirmation" required> 
      </div> 
      <div class="form-group"> 
      <button type="submit" class="btn btn-primary"> 
       Register 
      </button> 
      </div> 
     </div> 
     </form> 
     @if(count($errors)) 
     @foreach ($errors->all() as $error) 
      <div class="alert alert-danger"> 
      <p>{{ $error }}</p> 
      </div> 
     @endforeach 
     @endif 
    </div> 
    </div> 
</div> 
<!-- End Modal Register area --> 

は、その後、私はRegisterControllerの検証ルールを変更し、この新しい分野だけでなく、移行ファイルをインクルードする方法を作成します。あなたは私がルートにこれを掲示しています見ることができるような形態において

<?php 

namespace App\Http\Controllers\Auth; 

use App\User; 
use App\Http\Controllers\Controller; 
use Illuminate\Support\Facades\Validator; 
use Illuminate\Foundation\Auth\RegistersUsers; 
use Illuminate\Http\Request; 

class RegisterController extends Controller 
{ 
    /* 
    |-------------------------------------------------------------------------- 
    | Register Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller handles the registration of new users as well as their 
    | validation and creation. By default this controller uses a trait to 
    | provide this functionality without requiring any additional code. 
    | 
    */ 

    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) 
    { 
     return Validator::make($data, [ 
      'first_name' => 'required|max:255', 
      'last_name' => 'required|max:255', 
      'email' => 'required|email|max:255|unique:users', 
      'password' => 'required|min:6|confirmed', 
     ]); 
    } 

    /** 
    * Create a new user instance after a valid registration. 
    * 
    * @param array $data 
    * @return User 
    */ 
    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']), 
     ]); 
    } 
} 

(「登録」)が、にもかかわらず:

RegisterControllerを(だから、私は、データベース内のすべての良いそこをfiledsを持っています)私はフォームを送信するとエラーは出ませんし、/にリダイレクトされる/ユーザーはDBに保存されていません。 事実は、このデフォルト認証システムがどのように動作するかわかりません。

ご協力いただきありがとうございます。

+0

あなたがモデルにあなたの$充填可能なプロパティにフィールドを追加しました:

は、ここに私の更新のためのup()移行usersテーブル

public function up() { Schema::table('users', function (Blueprint $table) { $table->dropColumn('name'); $table->string('first_name')->nullable(); $table->string('last_name')->nullable(); }); } 

はまた新しいfillablesとUserモデルを更新していますか? –

+0

はい、私は言ったことを忘れていました。 –

+0

作成して作成するときに、追加する新しいフィールドはどこですか? –

答えて

0

私は提供されたコードがかなり正しいと思います。移行でnameフィールドフォームusersテーブルを削除したことを確認してください。

あなたのコードを使用して、あなたのモーダルとコントローラにユーザーを登録することができました。新鮮なLaravel 5.4でした。あなたのモーダルはwelcome.blade.phpに入っていました。また、CSS/jsファイルには、&モーダルを表示するボタンが追加されました。

protected $fillable = [ 
    'email', 'password', 'first_name', 'last_name' 
]; 
+0

Hmm ..私はmakeを実行した後に何をしましたか:authをデフォルトの認証にしました。私はユーザーの移行に直接行って、 'name'フィールドを削除した後、first_name、last_name 。その後、私はphp artisan migrateを実行しました。これが問題なのでしょうか? –

+0

はい、以前に実行されなかった場合は、既存の移行を変更できます。これは問題ではないはずです –

+0

私は最終的にこの実行を得ることができました。私は今、とても馬鹿だと感じています。問題は私のモーダルで、私はパスワードの検証に最低6を入れて忘れていました。 4文字のパスワードを入力してください。提出後にモーダルが終了するので、私はそれに気付かなかった。みんな、ありがとう! –