Laravel 5: how to redirect with data to external resource form controller

前端 未结 3 894
小蘑菇
小蘑菇 2021-02-10 09:27

I want to send user to payment gate. Normally it could be made by this form:

<
相关标签:
3条回答
  • 2021-02-10 09:51

    It could help you use the Laravel controller as usual and redirect after to the external resource.

    In your view redirect the action to your controller:

    <form method="post" action={{ action('Controller@method') }}>
        <input type="hidden" name="MNT_ID" value="12345678">
        <input type="hidden" name="MNT_TRANSACTION_ID" value="000001">
        <input type="hidden" name="MNT_CURRENCY_CODE" value="USD">
        <input type="hidden" name="MNT_AMOUNT" value="123.45">
        <input type="submit" value="Pay">
    </form>
    

    In your controller:

    public function method(Request $request)
    {
         // Validate
         // Store
         // ...
         Redirect::away('https://demo.moneta.ru/assistant.htm')->withInputs(Input::all());
    
    }
    

    I didn't test it, but I'm pretty sure that it works (or is near to the solution).

    You can get other suggestion from the official guide: http://laravel.com/docs/5.1/responses#redirects

    0 讨论(0)
  • 2021-02-10 09:59

    I think this is what you are looking for:

    call your function controller:

    public function redirectPOST(){
    //params
    $USERNAME='username';
    return view('your vie', compact('USERNAME'));}
    

    then in your view:

    <html xmlns="http://www.w3.org/1999/xhtml"><head>
    <script type="text/javascript">
     function closethisasap() {
     document.forms["redirectpost"].submit();
      }
     </script>
      </head>
     <body onload="closethisasap();">
     <form name="redirectpost" method="POST" action="http://URL">
     <input type="hidden" id="USERNAME" name="USERNAME" value="{{$USERNAME}}">
     </form>
     </body>
     </html>
    
    0 讨论(0)
  • 2021-02-10 10:00

    You can redirect to an external URL with Laravels's redirect. First import the Redirect to your controller and

    use Illuminate\Support\Facades\Redirect;
    return Redirect::away($redirectUrl)->with(['user_id'=>$user_id]);
    

    would help you to send the request as a post with the needed params.

    0 讨论(0)
提交回复
热议问题