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

rouckay's avatar

rouckay wrote a reply+100 XP

4mos ago

Add API to existing Laravel project

I have the same issue I can't able to write the logic for my app from scratch is there any way to generate the API from existance controller?

rouckay's avatar

rouckay liked a comment+100 XP

4mos ago

Add API to existing Laravel project

I think ideally you'll want dedicated api routes that use similar functionality. What that might look like in practice would be stripping logic out of your controllers into reusable traits so that your controller methods simply call the appropriate trait method to get data, and the controller responds either with a view template for your existing routes or with json for new api routes.

As for authentication, you'll likely want to use something like JWT