Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5: redirect to an external link outside of localhost/server

I want to build an app with laravel 5 & dropbox API in which I want the API allow/cancel-warning to be displayed when you land on the homepage, not when you click a button. I tried different methods but I couldn`t make it work.

public function start(){
        session(['user_id'=>1]);
        $dKey = 'key';
        $dSecret = 'secret';
        $appName = 'app';

        $appInfo = new Dropbox\AppInfo($dKey,$dSecret);

        //store csrf token
        $tokenStore = new  Dropbox\ArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');
        //define auth details
        $this->webAuth = new Dropbox\WebAuth($appInfo,$appName,'http://localhost:8000/dropbox/finish',$tokenStore);
        $this->checkSession();
    }

    public function checkSession(){
        $users = User::where('id','=',session('user_id'))->get();

        if(isset($user[0]->dropbox_token)){

        }
        else{
            $url = $this->webAuth->start();

            //return Redirect::to($url);
            //return Redirect::away($url);
            //header('Location : '.$url);
        }

    }

The link in $url exists and its valid.

These(last 3 commented methods) are the methods i tried , including return redirect($url),is it possible to do this or am i wasting my time with this ?please help me out.

like image 541
She Fu Avatar asked Mar 20 '15 01:03

She Fu


2 Answers

This code works for me:

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

Make sure you also add a return (i.e. return $this->checkSession();) in start().

like image 95
user94559 Avatar answered Sep 20 '22 05:09

user94559


Below code will work

return redirect()->away('http://www.paypal.com');

And this will also work.

return redirect('http://www.paypal.com');
like image 31
Pankaj Makwana Avatar answered Sep 19 '22 05:09

Pankaj Makwana