0

when user register, i need to pass registration field value to other controller also. this other controller will send information to outside api as post to register other websites.

I try to redirect with data but i think i just totally lost. this is my second controller

public function registerUser()
    {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, "http://api01.oriental-game.com:8085/register");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->xtoken);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
            "username" => "test2",
            "country" => "Korea",
            "fullname" => "Hihi User",
            "language" => "kr",
            "email" => "myuser123@test.com",
            "birthdate" => "1992-02-18"
        )));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $server_output = curl_exec($ch);
        curl_close($ch);
    }

when user register to our site, it will automatically create account in our own site and other 2 websites through their register api.

thanks in advance for your help.

bitmon
  • 3
  • 1
  • 4
  • Check this https://stackoverflow.com/questions/30365169/access-controller-method-from-another-controller-in-laravel-5 – Relaxed Leaf Jul 26 '19 at 18:16
  • but how to send form field data from registration page to above function and again pass to another functions? sorry kind of lost. – bitmon Jul 26 '19 at 18:28

1 Answers1

0

Instead of redirecting from function to function by means of HTTP redirects why not pass the form-data from your register form to a /register-user route and in the routes corresponding controller method catch the form data there.

Your form will post to something like this so make sure you have a route to first controller:

Route::get('/register-user', 'RegisterControllerNameHere@index');

Inside the first controllers function call the registerUser() in the second Controller like:

public function registerUser(Illuminate\Http\Request $request) {

(new \App\Http\Controllers\SecondControllerName)->registerUser($request>all());

}

Also allow for parameters to be passsed to the second controller:

public function registerUser($userData) // add parameter 

Now $userData will have the same data as the first controller which you can pass to your API call.

Does this help answer your question?

Devin Norgarb
  • 1,119
  • 13
  • 18