User Disable or pending in laravel
Comment (0)
Admin
172
Step 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 .
Step 2 :Create middleware
php artisan make:middleware UserStatus
app\Http\Middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class CheckStatus
{
/* * Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
//If the status is not approved redirect to login
if(Auth::check() && Auth::user()->status != 1){
Auth::logout();
return redirect('/login')->withErrors('Your Account Disabled !');
}
return $response;
}
}
Step 3 : Add middleware in Karnel
app\Http\Kernel.php
protected $routeMiddleware = [
'checkstatus' => \App\Http\Middleware\CheckStatus::class,
...
...
Step 4 : Create Route
You can use UserStatus middleware anywhere in route where you need
routes/web.php
Route::post('login',[LoginController::class , 'login'])->name('login')->middleware('UserStatus');
Step 5 : Show error message in blade file
to show message of disabled if account disabled user try to login
@if(Session::has('message')) <div class="alert alert-success"> {{ Session::get('message') }} </div> @endif
Hope it will help
Thanks !
Comments (0)
Your Comment