{"id":27370035,"url":"https://github.com/pod-point/laravel-configcat","last_synced_at":"2025-04-13T08:47:48.057Z","repository":{"id":70339823,"uuid":"602034716","full_name":"Pod-Point/laravel-configcat","owner":"Pod-Point","description":"Feature flags with Laravel using ConfigCat.","archived":false,"fork":false,"pushed_at":"2024-12-17T09:31:34.000Z","size":57,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-22T08:27:06.637Z","etag":null,"topics":["configcat","feature-flags","laravel","laravel-package"],"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/Pod-Point.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2023-02-15T11:08:04.000Z","updated_at":"2025-03-08T21:11:00.000Z","dependencies_parsed_at":"2023-11-08T12:25:22.000Z","dependency_job_id":"d87255c4-cf2e-453c-b0c2-668061d1695e","html_url":"https://github.com/Pod-Point/laravel-configcat","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"2d650f28e48021110ac60a9f2baaac24e946edb5"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pod-Point%2Flaravel-configcat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pod-Point%2Flaravel-configcat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pod-Point%2Flaravel-configcat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pod-Point%2Flaravel-configcat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pod-Point","download_url":"https://codeload.github.com/Pod-Point/laravel-configcat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688176,"owners_count":21145762,"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":["configcat","feature-flags","laravel","laravel-package"],"created_at":"2025-04-13T08:47:46.537Z","updated_at":"2025-04-13T08:47:48.051Z","avatar_url":"https://github.com/Pod-Point.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel ConfigCat\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/pod-point/laravel-configcat.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-configcat)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/pod-point/laravel-configcat/run-tests.yml?branch=main\u0026label=tests)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/Pod-Point/laravel-configcat/blob/main/LICENSE.md)\n[![Total Downloads](https://img.shields.io/packagist/dt/pod-point/laravel-configcat.svg?style=flat-square)](https://packagist.org/packages/pod-point/laravel-configcat)\n\nImplement feature flags within your Laravel application using [ConfigCat](https://configcat.com) cloud service.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require pod-point/laravel-configcat\n```\n\nFor Laravel 5.4 up to 9.x\n\n```bash\ncomposer require pod-point/laravel-configcat:^3.0\n```\n\n### Publishing the config file\n\nNext, you should publish the Laravel package configuration file using the `vendor:publish` Artisan command. It will be placed in your application's config directory:\n\n```bash\nphp artisan vendor:publish --provider=\"PodPoint\\ConfigCat\\ConfigCatServiceProvider\"\n```\n\nDon't forget to specify your [ConfigCat SDK `key`](https://app.configcat.com/sdkkey) within the freshly published Laravel configuration file under `config/configcat.php`.\n\nThe Laravel configuration for this package comes with sensible defaults. See [`config/configcat.php`](https://github.com/Pod-Point/laravel-configcat/blob/main/config/configcat.php) for more details.\n\n## Usage\n\n### Facade \u0026 global helper\n\nThe `ConfigCat` facade as well as the global helper can be used to retrieve the actual value of the feature flag, text or number setting:\n\n```php\nuse PodPoint\\ConfigCat\\Facades\\ConfigCat;\n\n$flag = ConfigCat::get('new_registration_flow');\n\n$flag = configcat('new_registration_flow');\n```\n\n\u003e **Note:** You can define the actual value of a feature flag to be `bool(true)` or `bool(false)` on ConfigCat but not only, it can also be [a number or a text setting](https://configcat.com/docs/main-concepts/#about-setting-types).\n\nIf the feature flag is undefined or something went wrong, `bool(false)` will be returned by default, however you can change this by specifying a default value **only when using the Facade or the global helper** to retrieve the feature flag value using:\n\n```php\nuse PodPoint\\ConfigCat\\Facades\\ConfigCat;\n\n$flag = ConfigCat::get('new_registration_flow', true);\n\n$flag = configcat('new_registration_flow', true);\n```\n\nYou can also globally sepcify a default value from the [`config/configcat.php`](https://github.com/Pod-Point/laravel-configcat/blob/main/config/configcat.php) file.\n\n:warning: **Only** `boolean`, `string`, `integer` or `float` default value types are supported as these are the only [setting types](https://configcat.com/docs/main-concepts/#about-setting-types) available from ConfigCat.\n\n### Validation rule\n\nGiven the following validation rules:\n\n```php\nValidator::make([\n    'email' =\u003e 'taylor@laravel.com',\n    'username' =\u003e 'taylor',\n], [\n    'email' =\u003e 'required_if_configcat:new_registration_flow,true',\n    'username' =\u003e 'required_if_configcat:new_registration_flow,false',\n]);\n```\n\n-   When the feature flag is **on**\n    -   The `email` will be a required field\n    -   The `username` will be an optional field\n-   When the feature flag is **off**, undefined, a text or number setting\n    -   The `email` will be an optional field\n    -   The `username` will be a required field\n\n### HTTP middleware\n\nThe following route will only be accessible if the [feature flag](https://configcat.com/docs/main-concepts/#about-setting-types) is truthy, otherwise a `404` will be thrown.\n\n```php\nRouter::get('/registration')-\u003emiddleware('configcat.on:new_registration_flow');\n```\n\nThe opposite is possible, also throwing a `404` if the feature flag is falsy:\n\n```php\nRouter::get('/sign-up')-\u003emiddleware('configcat.off:new_registration_flow');\n```\n\n**Note:** undefined, text or number settings will be considered as feature flags turned `off`.\n\n### Blade directive\n\nThe following view content will only be rendered if the feature flag is truthy:\n\n```blade\n@configcat('new_registration_flow')\n    New registration form\n@endconfigcat\n```\n\n```blade\n@unlessconfigcat('new_registration_flow')\n    Old registration form\n@endconfigcat\n```\n\n```blade\n@configcat('new_registration_flow_1')\n    Sign up\n@elseconfigcat('new_registration_flow_2')\n    Get started\n@else\n    Register\n@endconfigcat\n```\n\n**Note:** undefined, text or number settings will be considered as feature flags turned `off`.\n\n## Advanced usage\n\n### User targeting\n\nThe [User Object](https://configcat.com/docs/sdk-reference/php/#user-object) is essential if you'd like to use ConfigCat's [Targeting](https://configcat.com/docs/advanced/targeting) feature.\n\nConfigCat needs to understand the representation of your users from your application. To do so, you will need to transform your user into a `ConfigCat\\User` object. This can be done directly from the [`config/configcat.php`](https://github.com/Pod-Point/laravel-configcat/blob/main/config/configcat.php) file. Here is an example:\n\n```php\n'user' =\u003e \\PodPoint\\ConfigCat\\Support\\DefaultUserTransformer::class,\n```\n\nWhich will be using a sensible default transformer:\n\n```php\nclass DefaultUserTransformer\n{\n    public function __invoke(\\Illuminate\\Foundation\\Auth\\User $user)\n    {\n        return new \\ConfigCat\\User($user-\u003egetKey(), $user-\u003eemail);\n    }\n}\n```\n\nFeel free to create your own transformer class and use it instead, just **remember** that it needs to be **callable** with the `__invoke()` function.\n\n\u003e **Note:** for security reasons, all of the logic computation for the user targeting is executed on your application side of things using ConfigCat's SDK. No user details will be leaving your application in order find out wether or not a user should have a feature flag enabled or not.\n\nOnce you have defined your mapping, you will be able to explicitly use the representation of your user when checking a feature flag:\n\n```php\nuse App\\Models\\User;\nuse PodPoint\\ConfigCat\\Facades\\ConfigCat;\n\n$user = User::where('email', 'taylor@laravel.com')-\u003efirstOrFail();\nConfigCat::get('new_registration_flow', $default, $user);\n```\n\nThis is also applicable for the global helper and the Blade directive:\n\n```php\nconfigcat('new_registration_flow', $default, $user);\n```\n\n```blade\n@configcat('new_registration_flow', $user)\n    New registration form\n@endconfigcat\n```\n\n\u003e **Note:** if you have defined your user mapping but are not explicitly using a specific user when checking for a flag, we will automatically try to use the logged in user, if any, for convenience.\n\n### Caching \u0026 logging\n\nThis package supports native Laravel caching and logging capabilities in order to cache the feature flag values from ConfigCat's CDN as well as log any information when resolving feature flags. We've setup some sensible defaults but various levels of caching and logging can be configured.\n\nSee [`config/configcat.php`](https://github.com/Pod-Point/laravel-configcat/blob/main/config/configcat.php) for more info.\n\n### Test support: mock, fake \u0026 overrides\n\n#### In-memory testing\n\nWhen writing unit or functional tests, you may need to be able to mock or fake this package completely so you can test various behaviors within your application. This is all possible through the powerful Facade.\n\n**Mocking:**\n\n```php\nuse PodPoint\\ConfigCat\\Facades\\ConfigCat;\n\nConfigCat::shouldReceive('get')\n    -\u003eonce()\n    -\u003ewith('new_registration_flow')\n    -\u003eandReturn(true);\n```\n\nSee [https://laravel.com/docs/mocking#mocking-facades](https://laravel.com/docs/mocking#mocking-facades) for more info.\n\n**Fake:**\n\nFaking it will prevent the package to genuinely try to hit ConfigCat's CDN:\n\n```php\nuse PodPoint\\ConfigCat\\Facades\\ConfigCat;\n\n// you can fake it\nConfigCat::fake();\n// optionally setup some predefined feature flags for your test\nConfigCat::fake(['new_registration_flow' =\u003e true]);\n```\n\n#### End-to-end testing\n\nWhen running tests within a browser which doesn't share the same instance of the application, using mocks or fakes is not applicable. This is why we provide some overrides through ConfigCat SDK which will make the client under the hood localhost only and will use a locally generated `json` file in order to read the feature flags for the system under test.\n\nFirst of all, you will need to make sure to enable `overrides` from [`config/configcat.php`](https://github.com/Pod-Point/laravel-configcat/blob/main/config/configcat.php). You could also optionally tweak the file path for the `json` file if you wish to. The file will be automatically created for you when using overrides.\n\nSimilarly to `ConfigCat::fake()` you can come up with some predefined feature flags which will be saved into a `json` file:\n\n```php\nuse PodPoint\\ConfigCat\\Facades\\ConfigCat;\n\nConfigCat::override(['new_registration_flow' =\u003e true]);\n```\n\n## Testing\n\nRun the tests with:\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see our [Releases](https://github.com/pod-point/laravel-configcat/releases) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/Pod-Point/laravel-configcat/blob/main/CONTRIBUTING.md) for details.\n\n## Credits\n\n-   [configcat/php-sdk](https://github.com/configcat/php-sdk)\n-   [ylsideas/feature-flags](https://github.com/ylsideas/feature-flags) for inspiration\n-   [Pod Point](https://github.com/pod-point)\n-   [All Contributors](https://github.com/pod-point/laravel-configcat/graphs/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/Pod-Point/laravel-configcat/blob/main/LICENSE.md) for more information.\n\n---\n\n\u003cimg src=\"https://d3h256n3bzippp.cloudfront.net/pod-point-logo.svg\" align=\"right\" /\u003e\n\nTravel shouldn't damage the earth 🌍\n\nMade with ❤️\u0026nbsp;\u0026nbsp;at [Pod Point](https://pod-point.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpod-point%2Flaravel-configcat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpod-point%2Flaravel-configcat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpod-point%2Flaravel-configcat/lists"}