I would create the following Route::get('/profiles/{profile}', 'ProfileController@show');, if there is nothing exposed through the UI that has to be separated. Then I would allow access to those pages via policies only to the user whose profile it is and admin.
REST API routing and controller pattern questions
Hi all,
My team and I are building a REST API that is consumed by a Vue.js front-end, and have a few questions regarding it. I would be glad to get some insights or recommendations; thank you all in advance.
We have a user model and a profile model. The user has one profile, and the profile belongs to the user. At our application, a user is able to view and edit his own profile, but is also able to view the profile of some other user. However, if a user has an admin role (which is a boolean in the database for that user), the user is able to view and edit all profiles, as well as its own profile.
We are wondering how we would approach the creation of the controllers and routes for this.
Should we create a UserProfileController that has a method for viewing a profile of another user, so the route would be /user/{user}/profile, then create a controller for admins called AdminProfileController that has default CRUD for indexing, storing, showing, updating and deleting posts (route would be /admin/profiles/{profile}, and finally create a MeProfileController that only has the methods for performing CRUD for the profile of the currently authenticated user (route would be /me/profile)?
How would you guys do this? We thought of separating the controller logic since we have multiple roles. Is our way of thinking right here or is there a better way to do this?
Please or to participate in this conversation.