Skip to main content
Tutorial Free

Caffeine Package - prevent forms from timing out

February 09, 2016
2 min read
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!

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.