laravel基础文件。 我这样做是否正确?

In Laravel 5.1 I need to pass some data to the register view. The getRegister() function in RegistersUsers trait is responsible to return the view.

At first I modified the function to pass my data but then I realized that the modifications would be overridden in case of an update.

So I made a new controller registerController and modified the route for getRegister like this: Route::get('auth/register', 'Auth\RegisterController@getRegister')

Inside the controller I redefined the getRegister function to return the view with my additional data. Now I am thinking.. am I doing this correctly or do I need to use some other method and use the original AuthController some other way?

Also, default auth is set to use email for post login, how do I change it to use username without touching the foundation files?

Are all these matters regarding "extending the framework" ?

Thanks

First of all, it's always a bad idea to modify vendor files as the changes would be overwritten in case of any update in vendor package.

Answering your first question:

If you want to provide some additional data in registration view, you could do 2 things.

First one is to add your own getRegister() method:

public function getRegister()
{
    return view('auth.register')->with(<parameter name>, <parameter value>);
}

The drawback of this solution is that in case of any future changes in trait's getRegister method those changes will not be incorporated into your controller.

So the better approach is to reuse trait's getRegister() method in your controller and add your parameters to whatever trait returns:

In your controller do:

use RegistersUsers {
  RegistersUsers::getRegister as traitGetRegister;
}

public function getRegister()
{
    return $this->traitGetRegister()->with(<parameter_name>, <parameter_value>);
}

Answering your second question:

Laravel's Auth::attempt() method that is used to login users uses DatabaseUserProvider to load users from the DB and that provider is flexible enough to use any credential set you provide. However, if you want to use AuthenticatesUsers trait to login users, you have to override its postLogin method, because of the validation it does for user credentials:

$this->validate($request, [
  'email' => 'required|email', 'password' => 'required',
]);

UPDATE FOR LARAVEL 5.1: Since 5.1 there is no need to override postLogin() to change the column that is used to fetch users from the database. It is enough to set username property in the controller to the name of the column:

public $username = 'login';