{"id":22782197,"url":"https://github.com/randomstate/doctrine-scopes","last_synced_at":"2025-10-24T01:27:22.747Z","repository":{"id":62533179,"uuid":"174895170","full_name":"randomstate/doctrine-scopes","owner":"randomstate","description":"Global query builder scopes for Doctrine2","archived":false,"fork":false,"pushed_at":"2023-05-27T21:51:27.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T16:22:42.118Z","etag":null,"topics":["doctrine2","filters","multi-tenant","querybuilder","scopes"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/randomstate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-10T23:47:44.000Z","updated_at":"2023-05-27T21:51:27.000Z","dependencies_parsed_at":"2022-11-02T15:00:52.520Z","dependency_job_id":null,"html_url":"https://github.com/randomstate/doctrine-scopes","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomstate%2Fdoctrine-scopes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomstate%2Fdoctrine-scopes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomstate%2Fdoctrine-scopes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomstate%2Fdoctrine-scopes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/randomstate","download_url":"https://codeload.github.com/randomstate/doctrine-scopes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246333931,"owners_count":20760638,"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":["doctrine2","filters","multi-tenant","querybuilder","scopes"],"created_at":"2024-12-11T21:09:47.093Z","updated_at":"2025-10-24T01:27:17.690Z","avatar_url":"https://github.com/randomstate.png","language":"PHP","readme":"# Doctrine Scopes\n\nOne of the most important tasks in modern apps (particularly multi-tenant SaaS apps) is to ensure data isolation between your customers.\nThe 'best practice' for this is to filter all your queries at the global level.\n\nLaravel Eloquent provides it.\nDoctrine2 didn't.\n\nThis package fixes that 👌\n\n**This gives you the full power of the query builder for scoping your queries, whereas the built-in Filters doesn't allow joins and expects you to write the SQL yourself.**\n\n## Getting Started\n\n`composer require randomstate/doctrine-scopes`\n\n## Usage\n\nWhere you would normally create your entity manager, wrap it in a decoratable one and inject a scoped query builder factory closure.\n\n```php\n$scopes = new ScopeCollection();\n$scope-\u003eadd('myscope', new MyScope());\n$scope-\u003eenable('myscope');\n\n// Replace query builders with scopable ones\n$em = new DecoratableEntityManager(new EntityManager(...));\n$em-\u003esetQueryBuilderFactory(function() use($em, $scopes) {\n    return new ScopableQueryBuilder($em, $scopes);\n});\n\n// Wrap repositories so that they are scoped\n$em-\u003eextendRepositoryFactory(function(EntityRepository $repository) use($em) {\n    return new ScopedEntityRepository($repository, $em);\n})\n\n$em-\u003efind(MyClass::class, 1); // this query is now scoped by whatever you have in MyScope@apply 🎉\n```\n\n### Laravel\n\nFor laravel users, this is easier:\n\nAdd `RandomState\\DoctrineScopes\\DoctrineScopesServiceProvider::class` to your providers list in your `config/app.php` file.\n\nIn the boot method of a service provider of your choice (e.g. `AppServiceProvider`):\n```php\n\npublic function boot() {\n    $this-\u003eapp-\u003eextend(RandomState\\DoctrineScopes\\ScopeCollection::class, function($scopes) {\n        $scopes-\u003eadd('myscope', new MyScope);\n        $scopes-\u003eenable('myscope');\n        \n        return $scopes;\n    });      \n}\n\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandomstate%2Fdoctrine-scopes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frandomstate%2Fdoctrine-scopes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandomstate%2Fdoctrine-scopes/lists"}