0

Is there any elegant way to redirect to an external url with parameters in laravel?

I'm using this code:

$redirect = redirect(config('app.paypal.url') .'?'. http_build_query([
    'charset'       => 'utf-8',
    'paymentaction' => 'sale',
    'no_note'       => 1,
    ...
]));

but would prefer to use something like this (it doesn't work because the route is not defined):

$redirect = redirect(route(config('app.paypal.url'), [
    'charset'       => 'utf-8',
    'paymentaction' => 'sale',
    'no_note'       => 1,
    ...
]));
8ctopus
  • 341
  • 3
  • 10
  • Your first solution is already pretty elegant! That being said, I think this is the same issue as https://stackoverflow.com/questions/50816769/add-get-parameter-to-laravels-redirect-method – online Thomas Jun 04 '20 at 07:01
  • You may want to try this solution: https://stackoverflow.com/questions/44021662/how-to-create-global-function-that-can-be-accessed-from-any-controller-and-blade – Chester Alan Jun 04 '20 at 07:08
  • 1
    @onlineThomas thank you, however it doesn't work in my case because the route is external to laravel. exact error is route not defined. – 8ctopus Jun 04 '20 at 07:11
  • @ChesterAlan sorry I don't understand the relation with my question. can you explain? – 8ctopus Jun 04 '20 at 07:12

2 Answers2

1

You can do something like:

return redirect()->away('https://my.url.com')->with('user',$user)
                                ->with('pass_code',$pass_code)
                                ->with('amount',$amount)
                                ->with('hash_value',$hash_value);
                       
Rahul H
  • 41
  • 3
  • Further, has anyone managed to do a POST request on similar lines? I have been trying much, but haven't had a breakthrough. – Rahul H May 24 '21 at 06:08
0

Define the url you want to redirect in $url

Then just use

return Redirect::away($url);

Here is the simple example

return Redirect::away('http://www.google.com?q=lorem+ipsum');

Docs

Foued MOUSSI
  • 3,911
  • 2
  • 10
  • 30