{"id":20058350,"url":"https://github.com/originphp/multi_tenant","last_synced_at":"2026-07-06T22:31:33.134Z","repository":{"id":113276612,"uuid":"208737626","full_name":"originphp/multi_tenant","owner":"originphp","description":null,"archived":false,"fork":false,"pushed_at":"2021-01-05T12:27:15.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T09:45:16.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/originphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-16T07:31:40.000Z","updated_at":"2021-01-05T12:27:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0d73b31-aa07-43c6-b8d7-559ddb78eef9","html_url":"https://github.com/originphp/multi_tenant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/originphp/multi_tenant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originphp%2Fmulti_tenant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originphp%2Fmulti_tenant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originphp%2Fmulti_tenant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originphp%2Fmulti_tenant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/originphp","download_url":"https://codeload.github.com/originphp/multi_tenant/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/originphp%2Fmulti_tenant/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262944928,"owners_count":23388853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:01:17.364Z","updated_at":"2025-10-25T14:45:54.567Z","avatar_url":"https://github.com/originphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multi Tenant Plugin\n\nThe `MultiTenant` plugin enables you to make your web application multi-tenant using a single database.\n\n## Installation\n\n```linux\n$ bin/console plugin:install originphp/multi_tenant\n```\n\n## Models\n\nAdd the `Tenantable` trait to any model and then add the column `tenant_id` to your database (and schema)\n\n```php\nuse MultiTenant\\Tenantable;\n\nclass Contact extends ApplicationModel\n{\n    use Tenantable;\n}\n```\n\n## Initializing MultiTenant\n\nIn your AppController initialize the Tenant after you have loaded the `AuthComponent`.\n\n```php\nuse MultiTenant\\Tenant;\n\nclass AppController extends Controller\n{\n    protected function initialize() : void\n    {\n        $this-\u003eloadComponent('Auth');\n\n        if ($this-\u003eAuth-\u003eisLoggedIn()) {\n            $tenantId = $this-\u003eAuth-\u003euser('tenant_id');\n            Tenant::initialize($tenantId);\n        }\n    }\n}\n```\n\nBy default the Tenant class will use the `tenant_id` as the foreign key, if you want to use a different foreign key, then set this in the options when initializing the Tenant, here is an example:\n\n```php\nTenant::initialize($userId, [\n    'foreignKey' =\u003e 'user_id'\n]);\n```\n\nThat is it, as long the `Tenant` instance has been initialized, any model that finds will add the `tenant id` to query, and when you create a record the tenant id will be added automatically.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foriginphp%2Fmulti_tenant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foriginphp%2Fmulti_tenant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foriginphp%2Fmulti_tenant/lists"}