2017-12-24 12 views
-2

質問があります:どのようにリンクレジスタを変更できますか?例:正常な場合はauth - >私は経路abc.com/registerを持っています。Laravel - カスタムリンクレジスタとチェックバリデータ

しかし、私はそれをabc.com/register/usernameに変更したいのですが、ユーザー名はメンバー紹介です。登録すると、このユーザー名が存在するかどうかを確認できますか?代わりにAuth::routes()を呼び出す

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 = '/home'; 

    /** 
    * 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, [ 
      'name' => 'required|string|max:255', 
      'username' => 'required|string|max:255|unique:users', 
      '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) 
    { 

     return User::create([ 
      'name' => $data['name'], 
      'username' => $data['username'], 
      'email' => $data['email'], 
      'password' => bcrypt($data['password']), 
     ]); 
    } 
} 
+0

次に、定義済みのユーザー名のリストを作成します。私にとっては珍しいようです。私はむしろユーザに最初に登録させてから、 'domain.test/profile/{username} 'にリダイレクトします。 – Chay22

答えて

0

、手動でこれらのルートを登録し、必要に応じてそれらを変更:ユーザーテーブルを想定した(

// Authentication Routes... 
$this->get('login', 'Auth\[email protected]')->name('login'); 
$this->post('login', 'Auth\[email protected]'); 
$this->post('logout', 'Auth\[email protected]')->name('logout'); 

// Registration Routes... 
$this->get('register/{username}', 'Auth\[email protected]')->name('register'); 
$this->post('register/{username}', 'Auth\[email protected]'); 

// Password Reset Routes... 
$this->get('password/reset', 'Auth\[email protected]')->name('password.request'); 
$this->post('password/email', 'Auth\[email protected]')->name('password.email'); 
$this->get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset'); 
$this->post('password/reset', 'Auth\[email protected]'); 

をユーザ名が一意であることを確認するには、名前のためにあなたのバリデータのルールにexists:usersを追加名前はusersです)。

return Validator::make($data, [ 
    'name' => 'required|string|max:255|exists:users', 
    'username' => 'required|string|max:255|unique:users', 
    'email' => 'required|string|email|max:255|unique:users', 
    'password' => 'required|string|min:6|confirmed', 
]); 
+0

OPは' abc.com/register/username'の解決策を要求するので動作しません。だから、彼はusernameがURIの一部だと思っています。 –

+0

あなたはコードを更新しましたが、 'username'を傍受する必要があり、デフォルトの' showRegistrationForm 'はそれをしないので、まだ動作しません。また、検証も一切行いません。 –

+0

@AlexeyMezenin明らかに 'showRegistrationForm'や' register'関数をオーバーライドする必要があります。 –