【Laravel 5.1】 トレイト(trait)のメソッドを

【1】大元のトレイト AuthenticatesUsers

<?php

namespace Illuminate\Foundation\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;

trait AuthenticatesUsers
{
   use RedirectsUsers;

(中略) 

    /**
    * Get the path to the login route.
    *
    * @return string
    */
   public function loginPath()
   {
       return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login';
   }

   /**
    * Get the login username to be used by the controller.
    *
    * @return string
    */
   public function loginUsername()
   {
       /**
        * バックアップ用 return property_exists
        */
       return property_exists($this, 'username') ? $this->username : 'email';
       /**
        * [変更1] 
        *        (2019.12.01) 
        *         大元であるトレイトAuthenticatesUsersの
        *         loginUsernameメソッドを
        *         一旦変更してみたら、成功。
        * [変更2] 
        *        (2019.12.01) 
        *         しかしながら、vendor内をいじるのは、
        *         composer updateを実行した時に戻される可能性が高いので、
        *         Laravel 5.1では、AuthController.php側で 
        *         メソッドのオーバーライドを行うことにした。
        */
       // return property_exists($this, 'username') ? $this->username : 'name';
   }

(中略)

}





【2】トレイト AuthenticatesAndRegistersUsersはAuthenticatesをuseしている。

<?php

namespace Illuminate\Foundation\Auth;

trait AuthenticatesAndRegistersUsers
{
   use AuthenticatesUsers, 

       RegistersUsers 
   {
       AuthenticatesUsers::redirectPath insteadof RegistersUsers;
   }
}





【3】AuthControllerはトレイトAuthenticatesAndRegistersUsersをuseしている。

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
   /*
   |--------------------------------------------------------------------------
   | Registration & Login Controller
   |--------------------------------------------------------------------------
   |
   | This controller handles the registration of new users, as well as the
   | authentication of existing users. By default, this controller uses
   | a simple trait to add these behaviors. Why don't you explore it?
   |
   */

   use AuthenticatesAndRegistersUsers, ThrottlesLogins;

   /**
    * Create a new authentication controller instance.
    *
    * @return void
    */
   public function __construct()
   {
       $this->middleware('guest', ['except' => 'getLogout']);

       // ユーザーが作成された後は、tweets.indexへリダイレクト。
       $this->redirectPath = route('store.index');
       // ログインされた後は、tweets.indexへリダイレクト。
       $this->loginPath = route('store.index');
       // ログアウトされた後は、auth.getLoginへリダイレクト。
       $this->redirectAfterLogout = route('auth.getLogin');
   }

  

   public function loginUsername()
   {
       /**
        * バックアップ用 return property_exists
        */
       // return property_exists($this, 'username') ? $this->username : 'email';
       /**
        * 変更は以下 2019.12.01
        */
       return property_exists($this, 'username') ? $this->username : 'name';
   }
}