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

RonanH's avatar

How to structure an API

Hi,

I am trying to write my first API and am looking for some guidance on how to structure this in Laravel. I have Passport install and have created access token for the Authorization Grant Code and Personal Access Token Flows.

I had initially thought i would just put in the API endpoint routes into the routes/api.php file and then call a Controller i had setup for the API endpoint which would use an existing Model. However, i see that Laravel comes with Eloquent API resources and after having a read of the documentation i am not sure of the benefits of doing it this way as opposed to how i initially thought i would go about it. Can someone explain the advantages of doing this with Laravel Eloquent API resources?

Thanks

0 likes
3 replies
RonanH's avatar

Thanks for the help guys. I'll give the API Resources a go.

Please or to participate in this conversation.