Hello!
Got a pretty interesting question. There is an application on the bar, the whole is divided into a system of accounts for each company (by type of CRM). Do not confuse the company account with the user, it is different.
A company account has a slug, according to which the application determines which company the person contacts. Ie, for example, the following route: /account/*company_slug*/deals will return a transaction to a company whose slug = company_slug .
A /account/*company_slug*/ installed on the group of routes with the prefix /account/*company_slug*/ , which checks whether the current user has a role to perform actions in the company_slug company account .
In addition, each model that belongs to a certain company has an account_id field in the table, which defines the account to which it relates and does not allow other companies to gain access to someone else's infe.
But here's the task: in all tables, the connection goes exactly according to id in the account, and we receive only the slug account from the url at the entrance. Question: how do we get the account id for slug, which will be available from any model, service and controller, for all the further functioning of the application? What can be done to avoid using global variables?