Redirect to external URL with return in laravel

后端 未结 8 1411
野的像风
野的像风 2021-02-01 13:41

I am trying to send one time password to a user using SMS INDIA HUB API. For that purpose I need to redirect to a URL format:

http://cloud.smsindiahub.in/vendorsms/pushs

相关标签:
8条回答
  • 2021-02-01 13:53

    For Laravel 5.x / 6.x / 7.x use:

    return redirect()->away('https://www.google.com');
    

    as stated in the docs:

    Sometimes you may need to redirect to a domain outside of your application. You may do so by calling the away method, which creates a RedirectResponse without any additional URL encoding, validation, or verification:

    0 讨论(0)
  • 2021-02-01 14:04

    You can use Redirect::away($url)

    0 讨论(0)
  • 2021-02-01 14:05

    return Redirect::away($url); should work to redirect

    Also, return Redirect::to($url); to redirect inside the view.

    0 讨论(0)
  • 2021-02-01 14:06

    If you're using InertiaJS, the away() approach won't work as seen on the inertiaJS github, they are discussing the best way to create a "external redirect" on inertiaJS, the solution for now is return a 409 status with X-Inertia-Location header informing the url, like this:

    return response('', 409)
                ->header('X-Inertia-Location', $paymentLink);
    

    Where paymentLink is the link you want to send the user to.

    SOURCE: https://github.com/inertiajs/inertia-laravel/issues/57#issuecomment-570581851

    0 讨论(0)
  • 2021-02-01 14:07

    You should be able to redirect to the url like this

    return Redirect::to($url);
    

    You can read about Redirects in the Laravel docs here.

    0 讨论(0)
  • 2021-02-01 14:13

    Define the url you want to redirect in $url

    Then just use

    return Redirect::away($url);
    

    If you want to redirect inside your views use

    return Redirect::to($url);
    

    Read more about Redirect here

    Update 1 :

    Here is the simple example

    return Redirect::to('http://www.google.com');
    

    Update 2 :

    As the Questioner wants to return in the same page

    $triggersms = file_get_contents('http://www.cloud.smsindiahub.in/vendorsms/pushsms.aspx?user=efg&password=abcd&msisdn=9197xxx2&sid=MYID&msg=Hello');
    return $triggersms;
    
    0 讨论(0)
提交回复
热议问题