I ran into a "good practice question" when was trying to wrote an API for an authenticated user.
So, if I'm not writing an SPA, then i need an API for making axios(for example) request to get authenticated user's data. And i got kinda stuck.
If I'll put all user data routes in web.php, then my controller will be forced to return JSON for Vue to parse the data, which is not really a good practice for web.php routes.
If I'll put all user data routes in api.php, then it's a good practice to return JSON from it's controllers, but i won't be able to get an authenticated user simply with auth()->user() because api.php doesn't use an authenticated user session. So I'm forced to put a damn sanctum token for each of api request, which is a little:
- annoying
- not possible when rendering full page with vue
- might be considered bad practice
- can be avoided by simply putting all routes to
web.php
So, what is your opinion on where to put that kind of routes?