簡體   English   中英

Laravel 7 redirect away 在白頁上顯示重定向 url

[英]Laravel 7 redirect away shows redirect url on white page

I am redirecting away from Laravel 7 controller and it shows the redirection url just before it redirects to the url. 我正在使用以下代碼:

private function createPayment($session_token)
{
    ...

    try {
        $response = Http::timeout(30)->withHeaders($headers)->post($url, $body)->json();

        if ($response['statusCode'] != '0000') {
            $this->redirectError($response['statusCode'], $session_token);
        }

        $url= $response['bkashURL'];

        redirect()->away($url)->send();
    } catch (\Throwable $th) {
        $this->redirectError($response['statusCode'], $session_token);
    }
}

// 重定向錯誤方法:

private function redirectError($code, $session_token = null)
{
    if ($session_token != null) {
        session()->forget($session_token);
    }

    $message = $this->error($code);

    $url = config('global.api_url_bkash') . 'error/' . $message;

    redirect()->away($url)->send();
}

//錯誤方法:

private function error($code)
{
    switch ($code) {
        case '2001':
            return 'Invalid App Key';
            break;

        case '2002':
            return 'Invalid Payment ID';
            break;
            
    .....
}

我得到這個:

在此處輸入圖像描述

如何防止頁面不顯示 url。

不要使用send方法,只從 controller 方法返回響應 object。

public function index()
{
    // ...
    $url = config('global.api_url');
    
    return redirect()->away($url);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM