Question

How does a Laravel web application serve both a web-based front-end and native mobile app?

  1. Suppose for the web front-end we use a JS framework like AngularJS. Would the Laravel application consist of one API to serve both clients (web and native mobile)? Or would it be better to decouple these in some way and create two distinct APIs? Assuming the response will be JSON in this scenario, what would be the role of Laravel Views?

  2. How would the Laravel application differ if the web front-end is based on Blade templates, while the mobile application relies on JSON?

Was it helpful?

Solution

The app would have multiple route groups, the standard desktop site at / and then an API at /api/v* that is used by the mobile app and eventually by some Javascript code in the desktop site (for example a search function that loads results via AJAX).

In case of an API, there's no need for views, your controllers directly return JSON responses with Response::json() - and in some cases Laravel automatically takes care of that, for example you can directly return an instance of a model and the framework will automatically serialize it into JSON.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top