Best practice regarding controllers for a resource that can have different parent classes

Multi tool use


Best practice regarding controllers for a resource that can have different parent classes
I'm currently trying to refactor some controller code and I came accross some code that I'm not sure how to implement in a correct way.
My application has users and companies, and both can have projects.
The current situation is that we have 2 urls:
Those will route to the same controller which will handle the request differently based on if a company_id exists or not. This is not very clean in my opinion so I have been thinking about a better way to do this.
So far, I think the best way is to split them up in seperate controllers, like:
But since the only difference between a user project and a company project is pretty much that one has a 'user_id' and the other has a 'company_id', it feels like that will not be very DRY as I'll be writing a lot of duplicate code.
The current solution probably isn't as much of a problem, but I want to do this the correct way, so was hoping that someone over here would have a suggestion on how to handle this.
Thanks in advance!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.