laravel build in auth specify view to use

- 1 answer

Ad

Is there a way to specify what view to use for the built in auth in laravel? It currently uses views/auth/login.blade.php but i want for example to use views/admin/auth for the admin section then use another view for the front

Ad

Answer

Ad

when using the AuthenticatesUsers trait your controller will have getLogin, postLogin and getLogout methods which I think is what you are referencing on your routes, something like this:

Route::get('auth/login', 'Auth\[email protected]');
Route::post('auth/login', 'Auth\[email protected]');
Route::get('auth/logout', 'Auth\[email protected]');

If you give a look to AuthenticatesUsers the only thing it does is to check if view auth.authenticate exists if not it returns auth.login

You could override this method or create a new one with the view you want to return and change your route

class AuthController extends Controller
{
  public function newLogin()
  {
    return view('admin.auth');
  }
}

And change your Route to

Route::get('auth/login', 'Auth\[email protected]');

Another thing you could need in the future is to change the default login path and redirected after logout path, that can be done by defining in your controller two properties as protected:

protected $redirectAfterLogout = '/where/to/redirect/after/login';
protected $loginPath = '/another/login/path';
Ad
source: stackoverflow.com
Ad