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

dtirer@gmail.com's avatar

Laravel as Web App and API

I have an idea for an web app that I was going to build as both a website / php-web application, and as a native iPhone App. For the Web Application version, I was going to use Laravel.

What Im wondering is, whats the best way to share code between these two as far as endpoints go for the iPhone application? They're both going to need to retrieve the same data at the very least, so it'd be great to have them share that aspect.

In other words, whats the best practice for having a Laravel application serve both the browser-based application, and act as an API for the iPhone app?

0 likes
4 replies
bashy's avatar

Depending on a few things, you could return JSON (or whatever you want) depending on if a certain query_string is sent with the URI?

Mort's avatar

Do they need to share the same route structure? If not, then it's simple to namespace the routes to keep them seperate. Otherwise you could make use of user agent checking for handling the mobile specific queries.

dtirer@gmail.com's avatar

they don't need to share the same route structure. I'm more asking "what can they share, and how can i set that up in Laravel".

So if in the Web App, there's a page to get a User's Profile, you might have a UsersController with a show() method. And it pulls the data using the User Model. In the iPhone I'd like to use as much of that code as possible, so that if I have to change it down the line, it doesn't need to be changed in 2 places ( i know that particular User Profile scenario is a silly example )

rkity's avatar

use "Responsable interface" to use api as well as webapp.

Please or to participate in this conversation.