{"id":22827480,"url":"https://github.com/lacodix/laravel-global-or-scope","last_synced_at":"2025-04-23T13:44:10.741Z","repository":{"id":223352536,"uuid":"760087438","full_name":"lacodix/laravel-global-or-scope","owner":"lacodix","description":"A Laravel package to add possibility to use global scopes with an or operation in Eloquent models","archived":false,"fork":false,"pushed_at":"2024-09-15T14:57:38.000Z","size":86,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-21T06:51:55.290Z","etag":null,"topics":["eloquent","laravel","laravel-package","query","scopes"],"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/lacodix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"lacodix"}},"created_at":"2024-02-19T19:01:30.000Z","updated_at":"2024-09-15T14:57:42.000Z","dependencies_parsed_at":"2024-02-19T20:24:22.291Z","dependency_job_id":"900e195c-f72b-4349-baa4-5005bf304bbf","html_url":"https://github.com/lacodix/laravel-global-or-scope","commit_stats":null,"previous_names":["lacodix/laravel-global-or-scope"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-global-or-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-global-or-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-global-or-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-global-or-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lacodix","download_url":"https://codeload.github.com/lacodix/laravel-global-or-scope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250441629,"owners_count":21431191,"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":["eloquent","laravel","laravel-package","query","scopes"],"created_at":"2024-12-12T18:10:52.989Z","updated_at":"2025-04-23T13:44:10.721Z","avatar_url":"https://github.com/lacodix.png","language":"PHP","funding_links":["https://github.com/sponsors/lacodix"],"categories":[],"sub_categories":[],"readme":"# laravel-global-or-scope\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/lacodix/laravel-global-or-scope.svg?style=flat-square)](https://packagist.org/packages/lacodix/laravel-global-or-scope)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/lacodix/laravel-global-or-scope/test.yaml?branch=master\u0026label=tests\u0026style=flat-square)](https://github.com/lacodix/laravel-global-or-scope/actions?query=workflow%3Atest+branch%3Amaster)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/lacodix/laravel-global-or-scope/style.yaml?branch=master\u0026label=code%20style\u0026style=flat-square)](https://github.com/lacodix/laravel-global-or-scope/actions?query=workflow%3Astyle+branch%3Amaster)\n[![Total Downloads](https://img.shields.io/packagist/dt/lacodix/laravel-global-or-scope.svg?style=flat-square)](https://packagist.org/packages/lacodix/laravel-global-or-scope)\n\nThis package allows you to add global scopes to models combined with an or condition.\nIt contains additional functionality to disable some or all or-scopes on the fly.\n\n## Documentation\n\nYou can find the entire documentation for this package on [our documentation site](https://www.lacodix.de/docs/laravel-global-or-scope)\n\n## Installation\n\n```bash\ncomposer require lacodix/laravel-global-or-scope\n```\n\n## Basic Usage\n\nJust add the trait to your eloquent model and then you can use the addGlobalOrScopes method when booting.\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminate\\Database\\Eloquent\\Scope;\nuse Lacodix\\LaravelGlobalOrScope\\Traits\\GlobalOrScope;\n\nclass Post extends Model\n{\n    use GlobalOrScope;\n\n    public static function booting(): void\n    {\n        static::addGlobalOrScopes([Scope1::class, Scope2::class]);\n    }\n}\n\nclass Scope1 implements Scope\n{\n    public function apply(Builder $builder, Model $model)\n    {\n        return $builder-\u003ewhereNull('col1')-\u003ewhere('col2', 1);\n    }\n}\n\nclass Scope2 implements Scope\n{\n    public function apply(Builder $builder, Model $model)\n    {\n        return $builder-\u003ewhere('col3', 2);\n    }\n}\n...\nPost::query()-\u003ewhere('user_id', 1000)-\u003eget();\n```\n\nThis results in running the following SQL Query\n```sql\nselect * from \"posts\" where \"user_id\" = 1000 and ((\"col1\" is null and \"col2\" = 1) or (\"col3\" = 2))\n```\n\nFor temporary disabling you can use\n```php\nPost::query()-\u003ewithoutGlobalOrScopes()-\u003ewhere('user_id', 1000)-\u003eget();\n```\nwhat results in a simple\n```sql\nselect * from \"posts\" where \"user_id\" = 1000\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Contributing\n\nPlease run the following commands and solve potential problems before committing\nand think about adding tests for new functionality.\n\n```bash\ncomposer rector:test\ncomposer insights\ncomposer csfixer:test\ncomposer phpstan:test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\n- [lacodix](https://github.com/lacodix)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flacodix%2Flaravel-global-or-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flacodix%2Flaravel-global-or-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flacodix%2Flaravel-global-or-scope/lists"}