Download the PHP package genealabs/laravel-caffeine without Composer
On this page you can find all versions of the php package genealabs/laravel-caffeine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download genealabs/laravel-caffeine
More information about genealabs/laravel-caffeine
Files in genealabs/laravel-caffeine
Package laravel-caffeine
Short Description Keeping Your Laravel Forms Awake
License MIT
Informations about the package laravel-caffeine
โ Caffeine for Laravel
๐๏ธ Table of Contents
- ๐ Summary
- ๐ฆ Installation
- โ๏ธ Configuration
- ๐ Usage
- โ ๏ธ Considerations
- โฌ๏ธ Upgrading
- ๐ค Contributing
- ๐ Security
๐ Summary
Prevent forms from timing out when submitting them after leaving them on-screen for a considerable amount of time. Laravel defaults session lifetime to 120 minutes, but that is configurable and could be different site-by-site.
โ Caffeine works by sending a "drip" โ a lightweight AJAX request at regular
intervals โ to keep the session alive while a form is open. It only activates on
pages with a _token field or a csrf-token meta tag, so all other pages
time-out as normal.
๐ Why This Approach?
This package keeps the integrity of your site's security by avoiding the following:
- ๐ซ Exposing the CSRF Token on an unsecured endpoint.
- ๐ซ Eliminating CSRF Token validation on specific routes, or altogether.
- ๐ซ Removing session-timeout on all pages.
๐ Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
๐ฆ Installation
โจ The service provider is auto-discovered. No additional setup is required.
โ๏ธ Configuration
Only publish the config file if you need to customize it:
This creates the following config file:
๐ Usage
That's it! It will apply itself automatically where it finds a form with a
_token field, or a meta tag named "csrf-token", while pages are open in
browsers. ๐
๐ซ Prevent Caffeination
There are two methods to prevent Caffeine from keeping the session alive:
๐ท๏ธ Meta Tag Method
Add the following meta tag to any page you want to exclude:
๐ฃ๏ธ Route Middleware Method
Publish the config file and set use-route-middleware to true. This disables
the default global middleware mode. Then selectively enable Caffeine on specific
routes or route groups:
๐ Note: This will only have effect if the page includes a form. If not, the page will not caffeinate your application anyway.
โ ๏ธ Considerations
๐ Livewire / Inertia / SPA
This package works by injecting JavaScript that pings a keep-alive endpoint. It is designed for traditional Blade forms. If you are using Livewire or Inertia, their built-in request cycles typically keep the session alive already, so this package is generally unnecessary in those contexts.
๐ง Incompatible Packages
- Voyager has been reported as being incompatible. To work around this, configure Caffeine to use route-based middleware on all non-Voyager routes.
๐ค๏ธ Routes
This package registers routes under genealabs/laravel-caffeine.
โฌ๏ธ Upgrading
0.6.0
This update changed the config file setting names. Delete the published config
file config/genealabs-laravel-caffeine.php if it exists, and re-publish using
the command in the Configuration section.
For all other version changes, see the Releases page on GitHub.
๐ค Contributing
Contributions are welcome! ๐ Please review the Contribution Guidelines and observe the Code of Conduct before submitting a pull request.
๐งช Quality Checklist
- โ Achieve as close to 100% code coverage as possible using unit tests.
- โ Be fully PSR-1, PSR-4, and PSR-12 compliant.
- โ Provide an up-to-date CHANGELOG.md adhering to Keep a Changelog.
- โ Have no PHPMD or PHPCS warnings throughout all code.
๐ Security
If you discover a security vulnerability, please report it via GitHub Security Advisories rather than opening a public issue.
Built with โค๏ธ for the Laravel community using lots of โ by Mike Bronner.
This is an MIT-licensed open-source project. Its continued development is made possible by the community. If you find it useful, please consider ๐ becoming a sponsor and โญ starring it on GitHub.