{"id":21958663,"url":"https://github.com/mikebronner/laravel-caffeine","last_synced_at":"2025-10-08T16:33:32.153Z","repository":{"id":36424877,"uuid":"40729869","full_name":"mikebronner/laravel-caffeine","owner":"mikebronner","description":"Keeping Your Laravel Forms Awake.","archived":false,"fork":false,"pushed_at":"2025-03-18T12:38:17.000Z","size":564,"stargazers_count":929,"open_issues_count":0,"forks_count":84,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-12T20:43:36.211Z","etag":null,"topics":["laravel","middleware","package"],"latest_commit_sha":null,"homepage":"https://genealabs.com/docs/laravel-caffeine/","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/mikebronner.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["mikebronner"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2015-08-14T18:20:40.000Z","updated_at":"2025-04-11T11:47:55.000Z","dependencies_parsed_at":"2022-08-08T14:31:39.291Z","dependency_job_id":"5cb0d869-4438-4aba-84b8-034ee5ad7e9b","html_url":"https://github.com/mikebronner/laravel-caffeine","commit_stats":null,"previous_names":["genealabs/laravel-caffeine"],"tags_count":67,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebronner%2Flaravel-caffeine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebronner%2Flaravel-caffeine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebronner%2Flaravel-caffeine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebronner%2Flaravel-caffeine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikebronner","download_url":"https://codeload.github.com/mikebronner/laravel-caffeine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254168960,"owners_count":22026207,"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":["laravel","middleware","package"],"created_at":"2024-11-29T09:10:10.065Z","updated_at":"2025-10-08T16:33:27.092Z","avatar_url":"https://github.com/mikebronner.png","language":"PHP","funding_links":["https://github.com/sponsors/mikebronner"],"categories":[],"sub_categories":[],"readme":"# Caffeine for Laravel\n[![Travis](https://img.shields.io/travis/GeneaLabs/laravel-caffeine.svg)](https://travis-ci.org/GeneaLabs/laravel-caffeine)\n[![Scrutinizer](https://img.shields.io/scrutinizer/g/GeneaLabs/laravel-caffeine.svg)](https://scrutinizer-ci.com/g/GeneaLabs/laravel-caffeine)\n[![Coveralls](https://img.shields.io/coveralls/GeneaLabs/laravel-caffeine.svg)](https://coveralls.io/github/GeneaLabs/laravel-caffeine)\n[![GitHub (pre-)release](https://img.shields.io/github/release/GeneaLabs/laravel-caffeine/all.svg)](https://github.com/GeneaLabs/laravel-caffeine)\n[![Packagist](https://img.shields.io/packagist/dt/GeneaLabs/laravel-caffeine.svg)](https://packagist.org/packages/genealabs/laravel-caffeine)\n\n![Caffeine for Laravel masthead image.](https://repository-images.githubusercontent.com/40729869/26446500-f1b2-11e9-9611-6a2e65688de2)\n\n## Supporting This Package\nThis is an MIT-licensed open source project with its ongoing development made possible by the support of the community. If you'd like to support this, and our other packages, please consider [becoming a sponsor](https://github.com/sponsors/mikebronner).\n\nWe thank the following sponsors for their generosity. Please take a moment to check them out:\n\n- [LIX](https://lix-it.com)\n\n## Goal\nPrevent forms from timing out when submitting them after leaving them on-screen\n for a considerable amount of time. (Laravel defaults to 120 minutes, but that\n is configurable and could be different site-by-site.)\n\n## Implementation\nTo achieve this, we are sending a caffeine-drip (a request at regular intervals)\n to keep the session from timing out.\nThis is only implemented on pages with a `_token` field, so all other pages will\n time-out as normal.\n\n## Reasoning\nI chose this approach to keep the integrity of site-security, by avoiding the\n following:\n- exposing the CSRF Token on an unsecured endpoint.\n- eliminating CSRF Token validation on specific routes, or even altogether.\n- removing session-timeout on all pages.\n\n## Considerations\n### Incompatible Packages\n- [Voyager](https://github.com/the-control-group/voyager) has been reported as\n    being incompatible. To work around this, configure Caffeine to use\n    route-based middleware on all non-Voyager routes. See details below for\n    configuration and implementation of route-based middleware.\n\n### Routes\nThis package adds the routes under `genealabs/laravel-caffeine`.\n\n### Dependencies\nYour project must fullfill the following:\n- Laravel 8.0 or higher\n- PHP 7.3 or higher.\n\n## Installation\n```sh\ncomposer require genealabs/laravel-caffeine\n```\n\n## Upgrade Notes\nIf you have previously registered the middleware, please remove the following\n   middleware from `app/Http/Kernel.php`:\n   ```php\n   // protected $middleware = [\n       GeneaLabs\\LaravelCaffeine\\Http\\Middleware\\LaravelCaffeineDripMiddleware::class,\n   // ];\n   ```\n\n### 0.6.0\nThis update changes the config file setting names. Please delete the published\nconfig file `config/genealabs-laravel-caffeine.php` if it exists, and follow the\nconfiguration instructions below.\n\n## Configuration\n```php\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | Drip Interval\n    |--------------------------------------------------------------------------\n    |\n    | Here you may configure the interval with which Caffeine for Laravel\n    | keeps the session alive. By default this is 5 minutes (expressed\n    | in milliseconds). This needs to be shorter than your session\n    | lifetime value configured set in \"config/session.php\".\n    |\n    | Default: 300000 (int)\n    |\n    */\n    'drip-interval' =\u003e 300000,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Domain\n    |--------------------------------------------------------------------------\n    |\n    | You may optionally configure a separate domain that you are running\n    | Caffeine for Laravel on. This may be of interest if you have a\n    | monitoring service that queries other apps. Setting this to\n    | null will use the domain of the current application.\n    |\n    | Default: null (null|string)\n    |\n    */\n    'domain' =\u003e null,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Drip Endpoint URL\n    |--------------------------------------------------------------------------\n    |\n    | Sometimes you may wish to white-label your app and not expose the AJAX\n    | request URLs as belonging to this package. To achieve that you can\n    | rename the URL used for dripping caffeine into your application.\n    |\n    | Default: 'genealabs/laravel-caffeine/drip' (string)\n    |\n    */\n    'route' =\u003e 'genealabs/laravel-caffeine/drip', // Customizable end-point URL\n\n    /*\n    |--------------------------------------------------------------------------\n    | Checking for Lapsed Drips\n    |--------------------------------------------------------------------------\n    |\n    | If the browser tab is suspended due to inactivity or the device is put to \n    | sleep, it will still cause an error when trying to submit the form. To\n    | avoid this, we force-reload the form 2 minutes prior to session \n    | time-out or later. Setting this setting to 0 will disable this \n    | check if you don't want to use it.\n    |\n    | Default: 2000 (int)\n    |\n    */\n    'outdated-drip-check-interval' =\u003e 2000,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Use Route Middleware\n    |--------------------------------------------------------------------------\n    |\n    | Drips are enabled via route middleware instead of global middleware.\n    |\n    | Default: false (bool)\n    |\n    */\n    'use-route-middleware' =\u003e false,\n\n];\n```\n\n___Only publish the config file if you need to customize it___:\n```sh\nphp artisan caffeine:publish --config\n```\n\n## Usage\nThat was it! It will apply itself automatically where it finds a form with a\n`_token` field, or a meta tag named \"csrf-token\", while pages are open in\nbrowsers.\n\n### Prevent Caffeination\nThere are two methods to prevent Caffeine for Laravel from dripping to keep the\nsession alive: disabling it in Blade using the meta tag method, or enabling\nroute-middleware mode, and then only enabling it on routes or route groups.\n\n#### Meta Tag Method\nIf you would like to prevent a certain page from caffeinating your application,\nthen add the following meta tag:\n```php\n\u003cmeta name=\"caffeinated\" content=\"false\"\u003e\n```\n\n#### Route Middleware Method\nTo enable this mode, you need to publish the configuration file (see the\nconfiguration section above) and then set `use-route-middleware` to `true`. This\nwill disable the default global middleware mode (which applies it to any page\nthat has the CSRF token in it across your entire application). Now you need to\nselectively enable Caffeine on a given route or route group using route\nmiddleware:\n\n```php\nRoute::any('test', 'TestController@test')-\u003emiddleware('caffeinated');\n\nRoute::group(['middleware' =\u003e ['caffeinated']], function () {\n    Route::any('test', 'TestController@test');\n})\n```\n\nYou can still use the route middleware method and apply it globally to all\nroutes by editing `app/Http/Kernel.php` and adding it to the `web` middleware\ngroup. Although you should only use this option if you have a very specific use-\ncase that prevents you from utilizing the default global middleware option.\n\n__This will only have effect if the page includes a form. If not, the page will\nnot caffeinate your application anyway.__\n\n# The Fine Print\n## Commitment to Quality\nDuring package development I try as best as possible to embrace good design and\ndevelopment practices to try to ensure that this package is as good as it can\nbe. My checklist for package development includes:\n\n-   ✅ Achieve as close to 100% code coverage as possible using unit tests.\n-   ✅ Eliminate any issues identified by SensioLabs Insight and Scrutinizer.\n-   ✅ Be fully PSR1, PSR2, and PSR4 compliant.\n-   ✅ Include comprehensive documentation in README.md.\n-   ✅ Provide an up-to-date CHANGELOG.md which adheres to the format outlined\n    at \u003chttps://keepachangelog.com\u003e.\n-   ✅ Have no PHPMD or PHPCS warnings throughout all code.\n\n## Contributing\nPlease observe and respect all aspects of the included Code of Conduct\n\u003chttps://github.com/GeneaLabs/laravel-caffeine/blob/master/CODE_OF_CONDUCT.md\u003e.\n\n### Reporting Issues\nWhen reporting issues, please fill out the included template as completely as\npossible. Incomplete issues may be ignored or closed if there is not enough\ninformation included to be actionable.\n\n### Submitting Pull Requests\nPlease review the Contribution Guidelines \u003chttps://github.com/GeneaLabs/laravel-caffeine/blob/master/CONTRIBUTING.md\u003e.\nOnly PRs that meet all criterium will be accepted.\n\n## ❤️ Open-Source Software - Give ⭐️\nWe have included the awesome `symfony/thanks` composer package as a dev\ndependency. Let your OS package maintainers know you appreciate them by starring\nthe packages you use. Simply run `composer thanks` after installing this\npackage. (And not to worry, since it's a dev-dependency it won't be installed in\nyour live environment.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikebronner%2Flaravel-caffeine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikebronner%2Flaravel-caffeine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikebronner%2Flaravel-caffeine/lists"}