问题
I want to change the auth process to use another view template. E.g. instead of resources/views/auth/register.blade.php
it shall be used resources/views/register.blade.php
.
But I struggle to find the code where this view is called.
The only place I found was in app/Services/Register
but only if the validators fails. I need the place when the view is called per default.
回答1:
In AuthController, you can overwrite the method getRegister()
method like this :
public function getRegister()
{
return view('register');
}
Put this code in your AuthController.
回答2:
Laravel 5.6- I am extending Amarnasan's answer
In Laravel 5.6, there is no AuthController.php
. Instead of that, there are 4 different controllers.
LoginController.php
RegisterController.php
ForgotPasswordController.php
ResetPasswordController.php
To override the view of any Auth controller, Just look for the trait that Auth controller is using. Then, Go to that trait file and check which method is returning the default view for the Auth controller.
To change the default view for login
add the following in LoginController.php
public function showLoginForm() {
return view('auth.m-login');
}
To change the default view for Registration
add the following in RegisterController.php
public function showRegistrationForm() {
return view('auth.m-register');
}
To change the default view for Forgot password
add the following in ForgotPasswordController.php
public function showLinkRequestForm(){
return view('auth.passwords.m-email');
}
To change the default view for Reset password
add the following in ResetPasswordController.php
public function showResetForm(Request $request, $token = null){
return view('auth.passwords.m-reset')->with(
['token' => $token, 'email' => $request->email]
);
}
回答3:
I think you are looking for the trait
AuthenticatesAndRegistersUsers
in file Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers.php
used by the class
AuthController
in \App\Http\Controllers\Auth.php
. Specifically, the register view of your example is called in function getRegister
回答4:
in the class AuthController put this :
protected $registerView = 'directory.auth.register';
来源:https://stackoverflow.com/questions/32943578/laravel-5-override-the-default-view-for-registration-page