I have a situation where a company is managed by a user. i.e.: A user can create, read, update and delete their own companies. But I’d also like that same user to access a list of all companies in the system, even when logged out.
e.g.:
user_a manages the following companies: company_a and company_b
user_b manages the following companies: company_c and company_d
user_a should be able to see a list of his own companies (a and b) as well as a list of all companies (a, b, c, and d)
What’s the best way to handle this in the controllers?
Idealy, I’d like to have it setup under 2 separate routes as follows:
/companies
/users/1/companies
Should I have one controller for companies, or multiple? and how would that work?
I’m looking for best practices in this type of scenario.
IMHO if all user can see all companies it’s perfect to have one controller to get this job. Just in template you can check if current user is author of specified company and then add link to edit this company etc. if you want of course.