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

ahoi's avatar
Level 5

Use Laravel API from another Laravel-instance

Hello everybody,

I would like to ask you for articles on how to consume a Laravel API (I will call this Laravel Proviider) from another external Laravel instance (I will call this Laravel Client).

The Setup

The Laravel Provider is providing the API-routes for it's own vue/vuex/vue-router based frontend. To archive this, I integrated laravel/passport.

After running php artisan passport:install on the Laravel Provider I added the generated client id and the secret to .env to consume it in my LoginController like this:

        $request = Request::create('/oauth/token', 'POST', [
            'grant_type'    => 'password',
            'client_id'     => config('services.vue_client.id'),
            'client_secret' => config('services.vue_client.secret'),
            'username'      => $request->email,
            'password'      => $request->password,
        ]);

I guess I could authenticate users on the Laravel Client this way, too.

Open question

  • How do I allow the Laravel Client to access Laravel Server's API routes?
  • How do I create a second passport client without overwriting the others?
0 likes
1 reply
Nakov's avatar
Nakov
Best Answer
Level 73

You use passport as well. You can manage clients using Passport, each user has a different Token and lifetime for their token as well.

https://laravel.com/docs/master/passport#managing-clients

So the user that will consume the API will need to be registered in the Provider app which will generate the token for him, then he just copies that token to the client app and uses the API that way. Same as any other service, like Stripe or Mailgun..

1 like

Please or to participate in this conversation.