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

saidbakr's avatar

One app for web and API in Laravel

I able to create web application with blade views easily using Laravel, including authentication and authorization. However, I'm trying to find any resources, articles or tutorials, about the conjugation of the two scenarios in the following description:

I have ordinary web application using blade views, but in some views I would like to:

  1. Use JSON data output returned from other controller's actions using AJAX and VUE.
  2. Make that JSON output accessible with authentication and authorization via other applications using AJAX.

Indeed, the second point, is the more important for me, because the first functionality I can do it using jQuery. So, I need any suggestions for some resources meant by the second point as a first priority

0 likes
2 replies
StephenLake's avatar

Use JSON data output returned from other controller's actions using AJAX and VUE.

There's a general idea of keeping logic or engine code separate from your controllers so that you can call that code from anywhere within your application and not just through routing, I like to think of them as containers of functionality, or as they're more commonly called, 'repositories', classes stored away from your controllers but instantiated and called from anywhere including your controllers.

Check out Jeffrey's video on this: https://laracasts.com/lessons/repositories-simplified

Make that JSON output accessible with authentication and authorization via other applications using AJAX.

Can't quite say I fully understand this one, I mean - sounds like exactly what you're already doing with any controller/route/request. Simply create the HTTP from another source. You might need to install something like laravel-cors to allow cross-origin requests, but there isn't much more to it than what you've already done.

Laravel CORS: https://github.com/barryvdh/laravel-cors

1 like
saidbakr's avatar

@StephenLake , What I mean by the second point, is making authenticable and authorizable service. That service just accessible via AJAX for CRUD.

Please or to participate in this conversation.