DEV Community


Posted on

block user days doesn't work

Hi amazing people,

i had a question. i got a message that the days doesn't work for my login page. does somebody know what is wrong.

i will upload my code also here!

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class CheckBanned
* Handle an incoming request.
* @param Request $request
* @param Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return Response|RedirectResponse
public function handle($request, Closure $next)
if (auth()->check() && auth()->user()->banned_until && now()->lessThan(auth()->user()->banned_until)) {
$banned_days = now()->diffInDays(auth()->user()->banned_until);

        if ($banned_days > 14) {
            $message = 'Your account has been suspended ,Please contact administrator.';
        } else {
            $message = 'Your account has been suspended for '.$banned_days . $this->str_plural('days', $banned_days) .'. Please contact administrator.';

        return redirect()->route('login')->withMessage($message);

    return $next($request);
Enter fullscreen mode Exit fullscreen mode

this is the error Your account has been suspended for 2. Please contact administrator.

Discussion (0)