{"id":20428214,"url":"https://github.com/coderflexx/laravel-turnstile","last_synced_at":"2025-04-12T22:17:49.131Z","repository":{"id":170175858,"uuid":"646293243","full_name":"coderflexx/laravel-turnstile","owner":"coderflexx","description":"A package to help you implement the Cloudflare turnstile \"CAPTCHA Alternative\" into your laravel applications","archived":false,"fork":false,"pushed_at":"2025-03-01T13:16:23.000Z","size":54,"stargazers_count":81,"open_issues_count":2,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T22:17:45.337Z","etag":null,"topics":["captcha","cloudflare","laravel","laravel-turnstile","turnstile"],"latest_commit_sha":null,"homepage":"https://coderflex.com/open-source/docs/laravel-turnstile/introduction","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/coderflexx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2023-05-27T23:05:14.000Z","updated_at":"2025-03-11T08:57:39.000Z","dependencies_parsed_at":"2024-03-30T21:33:38.604Z","dependency_job_id":"b0c4beb6-3479-4f12-887d-318460758506","html_url":"https://github.com/coderflexx/laravel-turnstile","commit_stats":null,"previous_names":["coderflexx/laravel-turnstile"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravel-turnstile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravel-turnstile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravel-turnstile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderflexx%2Flaravel-turnstile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderflexx","download_url":"https://codeload.github.com/coderflexx/laravel-turnstile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637786,"owners_count":21137538,"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":["captcha","cloudflare","laravel","laravel-turnstile","turnstile"],"created_at":"2024-11-15T07:24:39.428Z","updated_at":"2025-04-12T22:17:49.111Z","avatar_url":"https://github.com/coderflexx.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Turnstile\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/coderflex/laravel-turnstile.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravel-turnstile)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/coderflexx/laravel-turnstile/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/coderflexx/laravel-turnstile/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/coderflexx/laravel-turnstile/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/coderflexx/laravel-turnstile/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/coderflex/laravel-turnstile.svg?style=flat-square)](https://packagist.org/packages/coderflex/laravel-turnstile)\n\n__Laravel Turnstile__, is a package to help you implement [cloudflare turnstile](https://developers.cloudflare.com/turnstile/) easily, and with no time.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require coderflex/laravel-turnstile\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"turnstile-config\"\n```\n\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | Turnstile Keys\n    |--------------------------------------------------------------------------\n    |\n    | This value is the site, and the secret key of your application, after creating an application\n    | with Cloudflare turnstile, copy the site key, and use it here, or in the .env\n    | file.\n    | Note that the secret key should not be publicly accessible.\n    |\n    | @see: https://developers.cloudflare.com/turnstile/get-started/#get-a-sitekey-and-secret-key\n    |\n    */\n    'turnstile_site_key' =\u003e env('TURNSTILE_SITE_KEY', null),\n\n    'turnstile_secret_key' =\u003e env('TURNSTILE_SECRET_KEY', null),\n\n    /*\n    |--------------------------------------------------------------------------\n    | Error Messages\n    |--------------------------------------------------------------------------\n    |\n    | Here you can find the error messages for the application. You can modify\n    | or translate the error message as you like.\n    |\n    | Note that you can translate the error message directly, without wrapping\n    | them in translate helper.\n    |\n    */\n    'error_messages' =\u003e [\n        'turnstile_check_message' =\u003e 'The CAPTCHA thinks you are a robot! Please refresh and try again.',\n    ],\n];\n```\n\n\nOptionally, you can publish the views using:\n\n```bash\nphp artisan vendor:publish --tag=\"turnstile-views\"\n```\n\n## Turnstile Keys\nTo be able to use __Cloudflare Turnstile__, you need to get the `SiteKey`, and the `SecretKey` from your [Cloudflare dashboard](https://developers.cloudflare.com/turnstile/get-started/#get-a-sitekey-and-secret-key)\n\nAfter Generating the __keys__, use `TURNSTILE_SITE_KEY`, and `TURNSTILE_SECRET_KEY` in your `.env` file\n\n```.env\nTURNSTILE_SITE_KEY=2x00000000000000000000AB\nTURNSTILE_SECRET_KEY=2x0000000000000000000000000000000AA\n```\n\nIf you want to test the widget, you can use the [Dummy site keys and secret keys](https://developers.cloudflare.com/turnstile/reference/testing/) that Cloudflare provides.\n\n## Usage\n\n### Turnstile Widget Component\n\nOnce you require this package, you can use the turnstile widget in your form, like the following\n\n```blade\n\u003cx-turnstile-widget \n    theme=\"dark\"\n    language=\"en-US\"\n    size=\"normal\"\n    callback=\"callbackFunction\"\n    errorCallback=\"errorCallbackFunction\"\n/\u003e\n```\n\nAs you can see, the widget has few options to use. You can know more about them in the [configuration section](https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#configurations)\n\n### Turnstile Backend Validation\n\nOnce you used the widget component, in the frontend. You can validate __Cloudflare__ Response, by using the `validate` method.\n\nHere's an example:\n\n```php\nuse Coderflex\\LaravelTurnstile\\Facades\\LaravelTurnstile;\n\npublic function store(Request $request)\n{\n    // maybe you want to validate your form first\n\n    $response = LaravelTurnstile::validate();\n\n\n    if (! $response['success']) { // will return boolean\n        // do your logic\n    }\n}\n```\n\nYou may, optionally, send the __Cloudflare__ response with the validation method. Something like the following:\n\n```php\npublic function store(Request $request)\n{\n    ...\n    $response = LaravelTurnstile::validate(\n        $request-\u003eget('cf-turnstile-response'); // this will be created from the cloudflare widget.\n    );\n    ...\n}\n```\n\n### Turnstile Custom Rule\nIf you want clean validation, you can use the `TurnstileCheck` custom rule, along with your form validation. Here's an example:\n\n```php\nuse Coderflex\\LaravelTurnstile\\Rules\\TurnstileCheck;\n\npublic function store(Request $request)\n{\n    $request-\u003evalidate([\n        'cf-turnstile-response' =\u003e [new TurnstileCheck()]\n    ]);\n}\n```\n\nThe custom rule, will use the same logic, as the __backend validation__, but instead will check for the response, and return a validation message, if the captcha fails.\n\nYou can change the content of the validation message, in `config/turnstile.php` file\n\n```php\nreturn [\n    ...\n    'error_messages' =\u003e [\n        'turnstile_check_message' =\u003e 'The CAPTCHA thinks you are a robot! Please refresh and try again.',\n    ],\n];\n```\n\n__PS__: If you want to translate the message, just copy the message and translate it, because it uses the translator method behind the scene.\n\n\n## Real Life Example\nIn your blade file\n\n```blade\n\u003cform action=\"\" method=\"post\"\u003e\n    @csrf\n    \u003cdiv\u003e\n        \u003cinput type=\"text\" name=\"name\" /\u003e\n        @error('name')\n            \u003cp class=\"error\"\u003e{{ $message }}\u003c/p\u003e\n        @enderror\n    \u003c/div\u003e\n\n    \u003cdiv\u003e\n        \u003cx-turnstile-widget theme=\"auto\" language=\"fr\"/\u003e\n        @error('cf-turnstile-response')\n            \u003cp class=\"error\"\u003e{{ $message }}\u003c/p\u003e\n        @enderror\n    \u003c/div\u003e\n\n    \u003cbutton\u003eSubmit\u003c/button\u003e\n\u003c/form\u003e\n```\n\nIn your controller:\n\n```php\nuse Coderflex\\LaravelTurnstile\\Rules\\TurnstileCheck;\nuse Coderflex\\LaravelTurnstile\\Facades\\LaravelTurnstile;\n\n...\n\npublic function store(Request $request)\n{\n    $request-\u003evalidate([\n        'name' =\u003e ['required', 'string', 'max:250'],\n        'cf-turnstile-response' =\u003e ['required', new TurnstileCheck()],\n    ]);\n\n    // or\n    $response = LaravelTurnstile::validate();\n\n    if (! $response['success']) {\n        // do your thing.\n    }\n\n    // do your things.\n}\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [ousid](https://github.com/ousid)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [the License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderflexx%2Flaravel-turnstile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderflexx%2Flaravel-turnstile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderflexx%2Flaravel-turnstile/lists"}