How to edit the routes created by the make: auth command?

3

I have a project in Laravel where I used the make:auth command to create the views , routes, controllers and etc from a registration form.

I need to change the view that is used by default in login to a view that I created the hand.

Doubt :

  • Can you edit this view or route?
  • If yes, where?
asked by anonymous 06.04.2017 / 20:05

2 answers

3

In this particular case of changing the views you will want to follow the recommendation of the friend @Wallace Maxters. This is the recommended way. ;)

In the event that you need to customize the routes, you can simply comment on the Auth::routes() line of the routes/web.php file and manually declare the routes by following the model of how they were declared (I am using Laravel 5.4 as a reference):

// 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...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');

// Password Reset Routes...
$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');

In order not to change anything in the code, you just have to keep the names of the routes and keep the same URL on the routes that repeat the URL, so you can for example translate the URL login to entrar since you do this on both the GET route and the POST route.

In general, you do not need to change the methods that the routes point to since you can overload them directly on the classes that they depend on. ;)

    
07.04.2017 / 02:57
5

This will depend on the version of Laravel you are using.

Laravel 5.2

You need to add the property $loginView to class AuthController .

So:

protected $loginView = 'nome_da_minha_view';

In the source code of trait called Illuminate\Foundation\Auth\AuthenticatesUsers , there is a method called showLoginForm , which is written like this:

/**
 * Show the application login form.
 *
 * @return \Illuminate\Http\Response
 */
public function showLoginForm()
{
    $view = property_exists($this, 'loginView')
                ? $this->loginView : 'auth.authenticate';

    if (view()->exists($view)) {
        return view($view);
    }

    return view('auth.login');
}

Note that if the loginView property exists in the current class (in this context it would be AuthController ), the view used will be the one defined in this property, if view also exists (according to the view()->exists() check).

Laravel 5.3 and 5.4

You simply need to override the method named showLoginForm in the authentication class and return to view desired.

  public function showLoginForm()
  {
        return view('minha_view_personalizada');
  }

There is yet another hint, which is to create the method called getLogin returning view . It will have the same effect as above with showLoginForm .

    
07.04.2017 / 02:03