Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel redirect to external api and send data to api

I am trying to initiate a function when the user clicks on action, the function will redirect the page to the external domain page for verification of data and return a response from there back to the Laravel page,


   public function connect($id)
    {
        
        $data = Api::where('id', $id)->first();

        return redirect()->away('https://api.xxx.com/login/dialog')->with([ 
            'client_id' => $data->api_key, 
            'redirect_uri' => $data->redirect_uri,
            'response_type' => 'code'],
     );
    }

Now, the external page does not see this array of data, So the question is how can I pass data to the external page for API verification and back to the original redirect page for further processing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Laravel redirect()->away() can only make GET requests and not POST request. In order to attach the query parameters you can take the following approaches:

return redirect()->away('https://example.com?param1=value1');

OR

$param1 = 'value1';
$url = 'https://example.com?param1=' . urlencode($param1);
return redirect()->away($url);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading