Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Solaiman Hossain's avatar

After giving client expire date middleware validation return redirect to dashboard not working properly

  1. I have created a middleware, the middleware name is expireDateCheck
  2. This middleware class I have kept to Kernel.php and I've added to this class protected $routeMiddleware.

Inside Kernel.php code is: protected $routeMiddleware = [ 'expireDateCheck' => \App\Http\Middleware\expireDateCheck::class, ]

  1. Then I've given a condition inside middleware expireDateCheck.php for redirecting to the dashboard, this condition working fine but the main problem is it's redirecting to the dashboard two times which means after showing dashboard then it's showing again dashboard page it seems like dashboard page loading multiple time.

How can I fix this problem?

Inside middleware expireDateCheck.php code is:


namespace App\Http\Middleware;

use Closure;
use App\User;
use App\Client;
use Auth;
use Redirect;

class expireDateCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (Auth::check() && Auth::user()){
            $currentDate = date('Y-m-d H:i:s');
            $userExpireDate = Client::where('expire_date', '<' , $currentDate)->first();
            
            if($userExpireDate){
                return Redirect::to('dashboard');
            }
            
            return $next($request);
        }
    }
}```
0 likes
10 replies
Snapey's avatar

use three backticks on a line before and after your codeblocks

You should know that when you return a redirect then this goes back to the client and they request instead the route you said to redirect to

So you need to ensure things like login and your dashboard route are not checked by this middleware or you just end up in a loop

Solaiman Hossain's avatar

This is my route group:

Route::group(['middleware' => 'expireDateCheck'],function(){ ---------- });

Route::get('dashboard','DashboardController@index')->middleware('admin');

Below the route group middleware, I've given a dashboard route but this problem is happening again.

tisuchi's avatar

@Solaiman Hossain What @sinnbeck meant is, wrap your code by 3 ``` so that it will be properly formatted.

For example-

Route::group(['middleware' => 'expireDateCheck'],function(){ 
	---------- 
});

Route::get('dashboard','DashboardController@index')->middleware('admin');
Snapey's avatar

What is Client and how does it relate to the Authenticated User ?

Solaiman Hossain's avatar

@Snapey Client is a company if the client has authenticated the user then will get permission to use WMS (Warehouse Management System) dashboard from third-party API WP admin app.

Snapey's avatar

@Solaiman Hossain But you are not checking if this user's access has expired? Just whatever the first client says ?

Probably a separate issue to your problem. How do you know the dashboard is called twice? Thats a specific number.

Solaiman Hossain's avatar

@Snapey Finally, I solved the issue, the main problem was inside the dashboard blade page Amchart sales by channel HTML div section, after giving expire date condition I have solved it. Thanks for your contribution.

Please or to participate in this conversation.