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

mstnorris's avatar

Use Lumen API for Laravel APP

Before I get too stuck in I want to make sure I'm on the right track.

<strongTL;DR

How do I go about using a Lumen API for a Laravel App?

Question

Let's say I have bought myproject.com through Hover and it's hosted on Digital Ocean set up via Laravel Forge.

I currently have two projects, a Lumen project called myproject-api and a Laravel project called myproject-app. When I deploy them I want to be able to use the Lumen API at api.myproject.com for the Laravel app at myproject.com. As I will also be developing a mobile app too (which will also use the Lumen API).

I would like to set up my Laravel project (myproject-app) to use the Lumen project (myproject-api) for all database related stuff.

How do I go about it with regards to routes etc, form submission. Could I encounter issues in the future when I deploy the apps?

0 likes
4 replies
ohffs's avatar

When I've done stuff like this I treat the API almost like a repository - so I have a class that I can call things like $this->users->getAll() where $this->users handles the guzzle/json/blah stuff. The front-end is treated like a normal laravel app as far as routing/forms etc goes.

Is that what you mean?

Could I encounter issues in the future when I deploy the apps?

No, it'll all be perfect - don't worry ;-p

mstnorris's avatar

It's more about the routes themselves, where I put them etc. Do I need to set up similar routes in my Laravel app as I would in my Lumen app?

Also how to use Guzzle (of which I'm not at all familiar). I'm watching Jeffrey's old Laravel 4 video now, and will look into more updated examples.

ohffs's avatar

I just have routes that make sense for the front-facing app defined within the front-facing app as if it had no knowledge that it was API backed rather than DB backed. The API end can do as it likes for routes etc - partly that depends if the API will be used by sources other than the web front end app (mobile apps or the like).

Last time I used guzzle it was fairly straightforward to use - but I seem to remember hearing it's had a fairly big (and not for the better) re-write recently, but I might be wrong. I've used httpful in the past too which worked fine for my (fairly simple) needs.

jekinney's avatar

If the apps are on the same server, I add each app to composers auto load. More so lumens to make use of the laravels models etc. no duplication!!!

Routes I keep separate for each app, the lumen routes I prefix with API/v1 (for example). If you want to call the routes in your Laravel app you can include the route file from lumin to Laravel with a require at the top of the Laravel routes.

Tip: change the default namespace from app to something distinct for Laravel and lumen.

Please or to participate in this conversation.