首页 > 解决方案 > 重定向到不在laravel中重定向的路由

问题描述

我一直在使用Laravel-5.8.35GET我正在通过表单调用请求。在我的路线上,我将form操作重定向controller 到提交表单的位置,但通过不同的路线重定向,例如,

$router->get('/merchant/sd-refund', 'Reports\ReportController@refundSecurityDeposit');

而且,在我的refundSecurityDeposit方法中,我调用了我的SohojSdRefundService服务,

    public function refundSecurityDeposit(Request $request)
    {
        // $userId, $reason, $sdAmount was fetched from the $request instance
        $this->execRefundRequest($userId, $reason, $sdAmount);
    }

    public function execRefundRequest($userId, $reason, $sdAmount)
    {
        // here the API service request data was handled,
        // and stored in $data instance

        return SohojSdRefundService::callSdRefundApi($data);
    }

当我的SohojSdRefundService服务完成处理时,我想将路线重定向到另一条路线,因为,

class SohojSdRefundService
{
    public function __construct()
    {

    }

    public static function callSdRefundApi($requestData)
    {
        // call to other methods inside the class to handle the API response,
        // and then return to the same route which isn't working

        return redirect('/admin/merchant/list');
    }
}

相应地,页面没有重定向到该路由,而是恰好仍然在最初提交的/merchant/sd-refund?...位置。form我重定向了另一个这样的服务,但它工作正常。任何人都可以建议我在这里实施错误吗?TIA。

标签: phplaravelroutes

解决方案


您需要在refundSecurityDeposit 函数中返回结果

public function refundSecurityDeposit(Request $request)
{

   return $this->execRefundRequest($userId, $reason, $sdAmount);
}

推荐阅读