A
A
arseniylebedev2019-01-15 15:51:02
Laravel
arseniylebedev, 2019-01-15 15:51:02

How to get the route to which the redirect occurs in the middleware?

I tried to do it like this:

$response = $next($request);

$route = Route::getRoutes()->match($response->getTargetUrl());

var_dump($route->getName());

But this does not work in match, you can only pass Request.
I need to get the route to which the redirect occurs, and get the list of middleware for this route.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin B., 2019-01-15
@arseniylebedev

In one of the projects, it was necessary to get the route done like this

$backRoute = app('router')->getRoutes()->match(app('request')->create(redirect()->back()->getTargetUrl()));
$backRouteName = $backRoute->getName();

H
hOtRush, 2019-01-15
@hOtRush

$request->route()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question