Home>

I made my own LoginController.php with the URL of the following Laravel 8.x document.
However, if this is the case, it is not possible to set the redirect destination after the account is locked, which is a problem.
If possible, go back to LoginController.php and get the error message there
I want to display (The number of login attempts has been exceeded. Lock for n minutes, etc.).

I would appreciate it if you could teach me here.
Thanks for your cooperation.

Referenced URL
https://laravel.com/docs/8.x/authentication#authenticating-users

Corresponding source code
<? php
namespace App \ Http \ Controllers;
use Illuminate \ Http \ Request;
use Illuminate \ Support \ Facades \ Auth;
class LoginController extends Controller
{
   /**
     * Handle an authentication attempt.
     *
     * @param \ Illuminate \ Http \ Request $request
     *
     * @return Response
     * /
    public function authenticate (Request $request)
    {
        $credentials = $request->only ('email','password');
        if (Auth :: attempt ($credentials)) {
            // Authentication passed ...
            return redirect ()->inverted ('dashboard');
        }
    }
}
Supplementary information (FW/tool version, etc.)

Laravel 8.x

  • Answer # 1

    I'm not sure if it's the correct method, but I solved it by the following method.

    /app/Exceptions/Handler.php

    use Throwable;
        public function render ($request, Throwable $exception) {
            if ($exception->getStatusCode () === 429) {
                // The number of authentication attempts exceeded the specified number
                return redirect ('login')->withErrors (['msg' =>['trial error']]);
            }
            return parent :: render ($request, $exception);
        }

  • Answer # 2

    You need to look at ThrottlesLoginTrait to see how it works, but to override it, why not add a property to LoginController?

      protected $maxAttempts = 3;// Default is 5
        protected $decayMinutes = 2;// Default is 1


    There is also documentation.
    https://laravel.com/docs/8.x/routing#rate-limiting