Custom Voyager Admin login with reCaptcha in Laravel

Shamil Omarov
Development Experiences
3 min readAug 2, 2019

These days I faced with a task to add reCaptcha to login of Voyager admin user and, of course, started looking for it on internet. As most of the guys did not find solution for it, and also the developers of Voyager answered that they use Login Throttle, so it can not be brute-forced. This is a good reason to give up on captcha, but what can you do when customer insists :) So, I decided to share my experience for others who will face the same issue. Before I start I would advice everyone to watch video series of Voyager Academy on their official website which helped me to find out solution to some issues.

Actually, Voyager provides everything for us to do so. There is view overriding ability, we can publish controllers to make changes and we can add additional style and script files. First, we create vendor/voyager directory in the resources/views folder of our project and create new view file named login.blade.php as in image below:

Now when you navigate to admin login page, page will be rendered using this file. You can create a completely new page or use voyager login blade file and change some parts. I went the second way and get the content of default login page from vendor/tcg/voyager/resources/views/login.blade.php. After I copied blade file content, I added reCaptcha using additional package.

Now we finished with view and can switch to controller part where we need to validate captcha. We need to navigate to config/voyager.php, find controllers array and change it to “App\\Http\\Controllers\\Voyager”:

After this we are ready to publish voyager controllers. Voyager has a very simple way of doing so. Just run the following command in console:

php artisan voyager:controller

Now we see a new folder in app/Http/Controllers named Voyager and consisting of all Voyager controllers. We have to open VoyagerAuthController and override validateLogin method.

This will validate login requests coming from new login page and so we wanted.

  • Note: If you added captcha to default login page of voyager as I did, it will affect frontend. I advice to add the foollwing line to new login.blade.php to avoid the problem:

overflow-y: scroll;

Now everything is ready and working! As an addition you can disable Login Throttling, but I would not advice it as extra security.

Good luck and have a working code!

--

--