how to redirect url before laravel check it in its web.php?

Viewed 136

i want to make a redirect panel and add some urls to it, if this urls are called(requested) it should redirect to new url before checking it in routes ->web.php file. i used a middleware for this and added the middleware to middlewares list in kernel but it doesn't work for some urls, what is the best solution?

kernel file

protected $middleware = [
        \App\Http\Middleware\TrustProxies::class,
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\CheckUrlMiddleware::class,

    ];

last middleware is the middleware that i created

CheckUrlMiddleware file

class CheckUrlMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        
        $url = urldecode($request->root().Request::getRequestUri());
        
        $url = Redirect_custom_url::where('old' , $url)->first();
        
        if ($url != null) {
            
            return Redirect::to($url->new);
        }
        return $next($request);
    }
}
0 Answers
Related