Laravel 5.8重定向返回200,但没有打开页面

时间:2019-06-06 15:15:03

标签: php laravel redirect

问题是我在一定条件下使用laravel redirect将用户重定向到特定的外部URL,并且条件为true,但是重定向仅登录到网络中,并没有真正更改浏览器中的URL。我也尝试在纯PHP中使用标头函数,但没有帮助。

这是我的代码:

public function purchase(Request $request, Transaction $transaction, User $user_model)
{
    $username = $request->input('username');
    if (!isset($username)) {
        $this->setMessage(400, 'پر کردن فیلد username الزامی است');
        return response()->json(['status' => 'error', 'data' => $this->getMessage()]);
    }
    $user = $user_model->scopeGetUserId($username);
    if ($user == null) {
        $this->setMessage(404, 'کاربر یافت نشد');
        return response()->json(['status' => 'error', 'data' => $this->getMessage()], 200);
    }
    $user_id = $user->id;
    $diet_type_id = $request->input('diet_type_id');
    $price = 100;

        $Amount = $price; //Amount will be based on Toman  - Required
        $Description = "پرداخت مبلغ $price تومان برای دریافت رژیم از سلامتپاد";  // Required
        $Email = 'm.esmiran@gmail.com'; // Optional
        $Mobile = '09123456789'; // Optional
        $CallbackURL = 'http://salamatpaad.com/test/public/api/verify/' . $user_id . '/' . $diet_type_id;  // Required
        $client = new SoapClient('https://ir.zarinpal.com/pg/services/WebGate/wsdl', array('encoding' => 'UTF-8'));

        $result = $client->PaymentRequest(
            array(
                'MerchantID' => $transaction->scopeGetMerchantId(),
                'Amount' => $Amount,
                'Description' => $Description,
                'Email' => $Email,
                'Mobile' => $Mobile,
                'CallbackURL' => $CallbackURL
            )
        );
        //Redirect to URL You can do it also by creating a form
        if ($result->Status == 100) {
            return redirect()->to('https://www.zarinpal.com/pg/StartPay/' . $result->Authority);
        } else {
            echo 'ERR: ' . $result->Status;
        }

}

response

1 个答案:

答案 0 :(得分:0)

Documentation中所述,要重定向到外部链接,请使用redirect()->away()方法。