小编Ash*_*din的帖子

如何从laravel redirectResponse获取重定向路由?

所以我试图测试我的 Laravel 的中间件,它将返回重定向。

如果请求不满足中间件的要求,请求将使用重定向 redirect()->route('name')

我尝试像这样从中间件获取返回值

$response = $middleware->handle($request, function ($req) { return $req; }, 'server:summary:view:edit');
\Log::info($response);
Run Code Online (Sandbox Code Playgroud)

$response实例Illuminate\Http\RedirectResponse。当我这样做时,\Log::info($response);我得到了这个结果。

HTTP/1.0 302 Found
Cache-Control: no-cache, private
Date:          Mon, 13 Jul 2020 08:12:27 GMT
Location:      https://myrandomurl.test/name

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://myrandomurl.test/name" />

        <title>Redirecting to https://myrandomurl.test/name</title>
    </head>
    <body>
        Redirecting to <a href="https://myrandomurl.test/name">https://myrandomurl.test/named</a>.
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

那么如何从 Location 标签中获取 url 呢?或如何从 laravel redirectResponse 获取重定向网址?

我尝试在https://laravel.com/api/5.8/Illuminate/Http/RedirectResponse.html#method_content浏览文档,但没有显示重定向路由的方法。

我需要这条路线来断言它以获得成功的测试结果。

php laravel

4
推荐指数
1
解决办法
570
查看次数

标签 统计

laravel ×1

php ×1