I would suggest using different controllers, using the same will give you fat controllers and unclean code. Common code can then be pushed either into the models, or into service classes.
Best practice for using the same controller function for web and API users.
Hi there,
This is my first time making an post here and I hope I've put it under the right channel. But I'm strugling with making an function of my controller available for API users and web users. I want to make an API endpoint which returns data with pagination and where the user is able to filter through JSON that he posts to the endpoint. I also want to make an headless web application with vue + nuxt where he can view and filter the data in a browser while also being able to extract it through the API. What is the best way to approach this? Is it for example creating/adding middleware for session and token based authentication or exposing that function to a route in the api.php file and web.php file or put an API access token in the users browser cookies or could it be something else?
Thanks in advance.
Please or to participate in this conversation.