Skip to content

Instantly share code, notes, and snippets.

@pantox
Last active February 27, 2019 16:59
Show Gist options
  • Save pantox/bba6f72b9e99263bbe301fb0c52562ec to your computer and use it in GitHub Desktop.
Save pantox/bba6f72b9e99263bbe301fb0c52562ec to your computer and use it in GitHub Desktop.
Laravel Authentication broken down
// install a fresh copy of Laravel 5.7, make:auth and migrate the database
// head over to yoururl.test/login and hit login button
resources/views/auth/login.blade.php
11 <form method="POST" action="{{ route('login') }}">
// the named route points to /login for GET and POST
routes/web.php
Auth::routes();
vendor/laravel/framework/src/Illuminate/Support/Facades/Auth.php
44 public static function routes(array $options = [])
vendor/laravel/framework/src/Illuminate/Routing/Router.php
1147 public function auth(array $options = [])
1151 $this->post('login', 'Auth\LoginController@login');
app/Http/Controllers/Auth/LoginController.php
21 use AuthenticatesUsers;
vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
31 public function login(Request $request)
if ($this->attemptLogin($request)) {
78 protected function attemptLogin(Request $request)
return $this->guard()->attempt(
$this->credentials($request), $request->has('remember')
);
// this->guard is default an instance of the defined guard, see config/auth.php
vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php
345 public function attempt(array $credentials = [], $remember = false)
// when the login attempt was ok, return true
102 protected function sendLoginResponse(Request $request)
109 ?: redirect()->intended($this->redirectPath());
vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
692 function redirect($to = null, $status = 302, $headers = [], $secure = null)
vendor/laravel/framework/src/Illuminate/Routing/Redirector.php
107 public function intended($default = '/', $status = 302, $headers = [], $secure = null)
vendor/laravel/framework/src/Illuminate/Foundation/Auth/RedirectsUsers.php
12 public function redirectPath()
// if exists calls the method or returns the property otherwise '/home'
// if something went wrong, return false
132 protected function sendFailedLoginResponse(Request $request)
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
app/Exceptions/Handler.php
47 public function render($request, Exception $exception)
vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php
168 public function render($request, Exception $e)
231 protected function convertValidationExceptionToResponse(ValidationException $e, $request)
249 protected function invalid($request, ValidationException $exception)
url()->previous()
vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php
154 public function previous($fallback = false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment