php – refactor Laravel Controller function to return the view based on the permission of the user

I have a route that switches routes according to the user's permission. Here is a small example:

public service show (Company $ company)
{
if (auth () -> user () -> hasPermission (& # 39; read-companies & # 39;)) {
return the view (& # 39; portal.company.showAdmin & # 39; compact (& # 39; company & # 39;));
} elseif (auth () -> user () -> hasPermission (& # 39; read-company & # 39;) && auth () -> user () -> companies-> contains ($ company)) {
return the view (& # 39; portal.company.showEntrepreneur & # 39; compact (& # 39;));
} elseif (auth () -> user () -> hasPermission (& # 39; read-companies_v & # 39;) && $ company-> visible ()) {
return the view (& # 39; portal.company.showTrainee & # 39; compact (& # 39;));
} other {
abort (& # 39; 403 & # 39;);
}
}

This basically amounts to 3 views depending on the permissions of the user. Most of my controller functions look like this. Now my question: Is this approach "A controller / route for multiple actions" a bad idea? And if I want to add a role to the auth () -> user () -> companies-> contains ($ enterprise) many to many relationship? I would need to add all my controller functions. Is it better to have a function on the user model as IsAbleToShowOnCompany ($ company)? But I would have lots of functions like that, because, for example, companies can create pokes, and I would need to check if the role of the many-to-many relationship in society allows.

Do you have refactor ideas?

I've heard about service classes and repository, but how can I rephrase that into a service?