{"id":36992125,"url":"https://github.com/sbine/simple-tenancy","last_synced_at":"2026-01-13T23:44:16.908Z","repository":{"id":62540752,"uuid":"233322813","full_name":"sbine/simple-tenancy","owner":"sbine","description":"Simple multi-tenancy for Laravel apps","archived":false,"fork":false,"pushed_at":"2025-06-18T04:18:30.000Z","size":20,"stargazers_count":37,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-26T01:39:05.139Z","etag":null,"topics":["hacktoberfest","laravel","multi-tenancy"],"latest_commit_sha":null,"homepage":"","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/sbine.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,"zenodo":null}},"created_at":"2020-01-12T01:38:34.000Z","updated_at":"2025-06-18T04:04:57.000Z","dependencies_parsed_at":"2023-12-16T22:37:38.424Z","dependency_job_id":"1aad3ab1-1652-4b73-af0e-ccb791eb485b","html_url":"https://github.com/sbine/simple-tenancy","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"6f07ea37f6e1386d2fa11232872556d08ea7c556"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/sbine/simple-tenancy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbine%2Fsimple-tenancy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbine%2Fsimple-tenancy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbine%2Fsimple-tenancy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbine%2Fsimple-tenancy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbine","download_url":"https://codeload.github.com/sbine/simple-tenancy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbine%2Fsimple-tenancy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["hacktoberfest","laravel","multi-tenancy"],"created_at":"2026-01-13T23:44:16.830Z","updated_at":"2026-01-13T23:44:16.898Z","avatar_url":"https://github.com/sbine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Laravel Multi-Tenancy\n\n![Build status](https://img.shields.io/github/actions/workflow/status/sbine/simple-tenancy/tests.yml?branch=main)\n\nSimple Tenancy adds automatic multi-tenant support to Eloquent models stored in a shared database.\n\nIt requires zero configuration in most cases, relying on established Laravel conventions and a single column on each table.\n\n### How it works\nUnder the hood, it has only 4 components:\n1. `Tenant`: Keeps track of the current user\n2. `HasTenancy`: A trait for models belonging to the tenant, which registers:\n3. `TenancyScope`: A [global scope](https://laravel.com/docs/master/eloquent#global-scopes) limiting all the model's queries to the current tenant\n4. `TenancyObserver`: An [observer](https://laravel.com/docs/master/eloquent#observers) which sets the current tenant column/identifier on save\n\nBy default, the tenant is Laravel's `Auth::user()`, and all tenancy checks are disabled when no one is authenticated.\n\n## Installation\n1. Install using Composer:\n```bash\ncomposer require sbine/simple-tenancy\n```\n\n2. Add the `HasTenancy` trait to all models belonging to the tenant:\n```php\nclass Account extends Model\n{\n    use \\Sbine\\Tenancy\\HasTenancy;\n}\n```\n\n3. Ensure a `user_id` column exists on the table of every model using the trait.\n\n## Customizing the tenant column/ID\nIf needed, you can customize the name of the tenant column or identifier by extending the Tenant class and [binding it into the container](#customizing-tenancy-behavior):\n```php\nclass MyTenant extends \\Sbine\\Tenancy\\Tenant\n{\n    /**\n     * Retrieve the column identifying each model's tenant.\n     */\n    public function column()\n    {\n        return 'tenant_hashid';\n    }\n\n    /**\n     * Retrieve the current tenant's identifier.\n     */\n    public function id()\n    {\n        return $this-\u003euser-\u003ehashid;\n    }\n}\n```\n\n## Customizing tenancy behavior\nBy default, if no user is authenticated tenancy will be completely disabled. This is by design so the library doesn't interfere with testing, seeding, and other unauthenticated model usage.\n\nTo change the tenancy behavior in any way, you can override the Tenant binding in the application container. \n\nFor example, to prevent all querying and saving of tenant models when no one is authenticated:\n```php\n    // In AppServiceProvider.php\n    public function register()\n    {\n        $this-\u003eapp-\u003esingleton(\\Sbine\\Tenancy\\Tenant::class, function () {\n            // Throw an AuthenticationException if auth check fails\n            return new \\Sbine\\Tenancy\\Tenant(Auth::authenticate());\n        });\n    }\n```\n\nTo allow overriding tenancy checks based on a policy or method, pass a callback returning `true` or `false`:\n```php\n    // In AppServiceProvider.php\n    public function register()\n    {\n        $this-\u003eapp-\u003esingleton(\\Sbine\\Tenancy\\Tenant::class, function () {\n            return new \\Sbine\\Tenancy\\Tenant(Auth::user(), function ($user) {\n                return $user-\u003ecan('admin');\n            });\n        });\n    }\n```\n\nFor complete control over tenant behavior, you can bind your own Tenant implementation:\n```php\n    // In AppServiceProvider.php\n    public function register()\n    {\n        $this-\u003eapp-\u003esingleton(\\Sbine\\Tenancy\\Tenant::class, function () {\n            return new MyTenant;\n        });\n    }\n```\n\n## Disabling tenancy\nFor convenience, a SuperAdmin class is provided which you can bind at any time to disable tenant checks:\n```php\n    $this-\u003eapp-\u003esingleton(\\Sbine\\Tenancy\\Tenant::class, \\Sbine\\Tenancy\\SuperAdmin::class);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbine%2Fsimple-tenancy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbine%2Fsimple-tenancy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbine%2Fsimple-tenancy/lists"}