Caffeine Package - prevent forms from timing out

If you have a longer form in your project, it takes time to fill it in. And if it's hidden under user session, it will time out - by default, in 120 minutes. Seems like enough time, but what if a user left the form open for longer time, went for coffee or something, and then tries to finish it after a while? There is a package to make session active. It's called Caffeine for Laravel (I guess, the name means "a medicine for Laravel form not to fall asleep"). It works in a really simple way - by sending background ajax requests to server from time to time, therefore making session active. How to use it: 1. Composer require:
composer require genealabs/laravel-caffeine:~0.3.0
(or different version 0.2.0 for Laravel 5.1) 2. Service Provider:
GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider::class,
3. Additional middleware in app/Http/Kernel.php:
protected $middleware = [
  // ...
  \GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware::class,
];
By default, the package sends refresh requests every 5 minutes. You can change that time interval by changing the config. But first you need to publish it:
php artisan vendor:publish --tag=genealabs-laravel-caffeine
And then go to /app/config/genealabs-laravel-caffeine.php file to change settings. Expecting more information? No, that's it - simple package to effectively achieve one simple function. Great work and respect to author Mike Bronner!

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month

Written by