<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class ForcePasswordChange
{
    public function handle(Request $request, Closure $next)
    {
        $user = $request->user('admin');

        if ($user && $user->must_change_password && !$request->routeIs('admin.password.change*')) {
            return redirect()->route('admin.password.change');
        }

        return $next($request);
    }
}
