Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

API Request

How to develop User Login & Registration from one Laravel project to another Laravel project using API Request ?

0 likes
6 replies
sr57's avatar

You have to write the code to sync the users table between the 2 apps

Other solutions :

1 like
afoysal's avatar

Thanks @sr57 . Actually it's not DB issue. Is it possible to use API request in one Laravel system of another Laravel system ?

afoysal's avatar

Thanks @sr57 . Thanks for sharing the link. Could you please show me some code example regarding this ?

I used Laravel API for Vue.js & React.js application before. I can develop API using Laravel also.

sr57's avatar

Nothing difficult

  • Define your route in api.php, for instance

Route::post('start', 'App\Http\Controllers\GameController@play');

  • in your code, get your parameters via $request (like web page) , get your confidential data by connecting to the 'input db' and update your 'output db'

    public function play( Request $request ) { ...

I have to leave till Monday, try by yourself and ask other specific(s) question(s) if needed.

1 like
victorD's avatar

Not sure if it is what you are looking for, but here an example of how I do api post :

 $params = [
            'action' => 'activities',
            'lang' => 'fr',
            'filtre' => $this->filtre,
            'index' => $this->index,
           'quantity'=>$this->quantity,
           'source'=> $this->source,
            ];

         $response =  $this->callAPIwithPostV2("/activities",$params);

         return $response;



private function callAPIPostCore($path, $parameters, $url = null)
{
if($url == null)
        {
            $url = env('APP_URL');
        }
        
        $addedApiPath = "/api";
        
        $token = env('X_API_KEY');
        $headers = [
            'Content-Type' => 'application/json',
            'X-API-KEY'=> "".$token."",
        ];
        $baseUrl = $url.$addedApiPath;
        $url = "".$baseUrl.$path."";
        $formParams = $parameters;

        $client = new \GuzzleHttp\Client(['headers' => $headers]);
        $request = $client->post($url,['form_params' => $formParams]);
        
        return $request;
}

  public function callAPIwithPostV2($path, $parameters, $url = null)
    {
        $request = $this->callAPIPostCore($path, $parameters, $url);
        $response = $request->getBody();
        
        return json_decode($response);
    }
    

1 like

Please or to participate in this conversation.