Table of Contents
- 1) Create status columin users table and also mention in User.php modal
- 2) Add below middleware CheckStatus.php inside app\Http\Middleware
- 3) Add below inside app\Http\Kernel.php
- 4) Put below inside routes files routes/web.php
- 5) You can put below inside login.blade.php file resources\views\auth\login.blade.php
Laravel is an open-source PHP web framework that was created as an enhanced alternative to the CodeIgniter framework . Its architectural designs are heavily influenced by Symfony.
With around 45000 ratings, Laravel is also one of the most popular repositories on GitHub (and counting). This framework gained popularity following the release of features such as the Artisan Command Line Interface, database support, and migrations. It also featured a new packing mechanism known as bundles. The Laravel framework is best suited for all types of web application development, from small to large.
Most of the time in our dynamic website, we require user dashboard features. And we also need to enable or disable the user from login to our website . By default Laravel do not allow this feature . As a website developer we need to make this feature because lots of our client require this in their laravel website .
Today I in this tutorial i will guide step by step on how to disable user login when hi/her account disabled.
To prevent login for account when user disabled.
1) Create status columin users table and also mention in User.php modal
Open your phpmyadmin and access the laravel database of your project . Now go to users table and create 'status' column . Data type should 'int' and default value 0 for default registered account considered disabled .2) Add below middleware CheckStatus.php inside app\Http\Middleware
This will check users table column 'status' value. If it won;t found 1 then it logout the user before procedding .3) Add below inside app\Http\Kernel.php
It will register our Middleware class to Kernel.php4) Put below inside routes files routes/web.php
It will override and add middleware to disable login for status 0 user5) You can put below inside login.blade.php file resources\views\auth\login.blade.php
to show message of disabled if account disabled user try to login
Well, I have not covered the backend part that handle this status field value update 'active' or 'inactive'.
You can make yourself , it's easy like you make for other field in normal CRUD system .
Finally if you make status field value 0 (means) disabled and try to login the user from frontend then you can't login .
In this way we achieved prevent login the user whose account is disabled. I am a Web Developer working since 2008 ,having experience more than 12 years.
You can contact is, If you looking to hire Laravel Web Developer.