1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【laravel】Authのルーティング

Last updated at Posted at 2020-05-22

概要

AuthのルーティングはRESTfulを利用しているため、ログインや新規登録を編集するために調べました。

Authのルーティング

Authのルーティングは\vendor\laravel\framework\src\Illuminate\Routingのauthメソッドに記述されています。
authメソッドはオプション引数として配列型の$optionsが用意されており、引数に入る値次第でif文により条件分岐させています。

ここでは見やすいように、コメントや条件分岐によるメソッドの使用を一旦無視した内容を載せます。
詳細は次の段落に載せます。

web
Auth::routes();
Router.php
public function auth(array $options = [])
{
  // Authentication Routes...
  $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
  $this->post('login', 'Auth\LoginController@login');
  $this->post('logout', 'Auth\LoginController@logout')->name('logout');

  // Registration Routes...
  if ($options['register'] ?? true) {
    $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    $this->post('register', 'Auth\RegisterController@register');
  }

  // 以下よりif文で条件分岐して別メソッドへ
  // Password Reset Routes...
  // Password Confirmation Routes...
  // Email Verification Routes...
}

// Password Reset Routes...
public function resetPassword()
{
  $this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
  $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
  $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
  $this->post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');
}

// Password Confirmation Routes...
public function confirmPassword()
{
  $this->get('password/confirm', 'Auth\ConfirmPasswordController@showConfirmForm')->name('password.confirm');
  $this->post('password/confirm', 'Auth\ConfirmPasswordController@confirm');
}

// Email Verification Routes...
public function emailVerification()
{
  $this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
  $this->get('email/verify/{id}/{hash}', 'Auth\VerificationController@verify')->name('verification.verify');
  $this->post('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
}

詳細

各メソッドをそのまま転記します。
気になるところがあれば追記します。

auth()

Router.php
/**
 * Register the typical authentication routes for an application.
 *
 * @param  array  $options
 * @return void
 */
public function auth(array $options = [])
{
  // Authentication Routes...
  $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
  $this->post('login', 'Auth\LoginController@login');
  $this->post('logout', 'Auth\LoginController@logout')->name('logout');

  // Registration Routes...
  if ($options['register'] ?? true) {
    $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    $this->post('register', 'Auth\RegisterController@register');
  }

  // Password Reset Routes...
  if ($options['reset'] ?? true) {
    $this->resetPassword();
  }

  // Password Confirmation Routes...
  if (
    $options['confirm'] ??
    class_exists($this->prependGroupNamespace('Auth\ConfirmPasswordController'))
  ) {
    $this->confirmPassword();
  }

  // Email Verification Routes...
  if ($options['verify'] ?? false) {
    $this->emailVerification();
  }
}

resetPassword()

Router.php
/**
 * Register the typical reset password routes for an application.
 *
 * @return void
 */
public function resetPassword()
{
  $this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
  $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
  $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
  $this->post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');
}

confirmPassword()

Router.php
/**
 * Register the typical confirm password routes for an application.
 *
 * @return void
 */
public function confirmPassword()
{
  $this->get('password/confirm', 'Auth\ConfirmPasswordController@showConfirmForm')->name('password.confirm');
  $this->post('password/confirm', 'Auth\ConfirmPasswordController@confirm');
}

emailVerification()

Router.php
/**
 * Register the typical email verification routes for an application.
 *
 * @return void
 */
public function emailVerification()
{
  $this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
  $this->get('email/verify/{id}/{hash}', 'Auth\VerificationController@verify')->name('verification.verify');
  $this->post('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
}

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?