【问题标题】:Redirect to route not redirecting in laravel重定向到不在laravel中重定向的路由
【发布时间】:2021-07-22 16:24:31
【问题描述】:

我一直在使用Laravel-5.8.35。我正在通过表单调用GET 请求。在我的路线上,我将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');
    }
}

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

【问题讨论】:

    标签: php laravel routes


    【解决方案1】:

    你需要在refundSecurityDeposit函数中返回一个结果

    public function refundSecurityDeposit(Request $request)
    {
    
       return $this->execRefundRequest($userId, $reason, $sdAmount);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-09
      • 2017-06-19
      • 2021-04-26
      • 2017-04-12
      • 2014-09-16
      • 2015-11-09
      • 1970-01-01
      • 2018-12-27
      相关资源
      最近更新 更多