This 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.
Prevent forms from timing out when submitting them after leaving them on-screenfor a considerable amount of time. (Laravel defaults to 120 minutes, but thatis configurable and could be different site-by-site.)
To achieve this, we are sending a caffeine-drip (a request at regular intervals)to keep the session from timing out.This is only implemented on pages with a _token
field, so all other pages willtime-out as normal.
I chose this approach to keep the integrity of site-security, by avoiding thefollowing:
This package adds the routes under genealabs/laravel-caffeine
.
Your project must fullfill the following:
composer require genealabs/laravel-caffeine
If you have previously registered the middleware, please remove the followingmiddleware from app/Http/Kernel.php
:
// protected $middleware = [
GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware::class,
// ];
This update changes the config file setting names. Please delete the publishedconfig file config/genealabs-laravel-caffeine.php
if it exists, and follow theconfiguration instructions below.
return [
/*
|--------------------------------------------------------------------------
| Drip Interval
|--------------------------------------------------------------------------
|
| Here you may configure the interval with which Caffeine for Laravel
| keeps the session alive. By default this is 5 minutes (expressed
| in milliseconds). This needs to be shorter than your session
| lifetime value configured set in "config/session.php".
|
| Default: 300000 (int)
|
*/
'drip-interval' => 300000,
/*
|--------------------------------------------------------------------------
| Domain
|--------------------------------------------------------------------------
|
| You may optionally configure a separate domain that you are running
| Caffeine for Laravel on. This may be of interest if you have a
| monitoring service that queries other apps. Setting this to
| null will use the domain of the current application.
|
| Default: null (null|string)
|
*/
'domain' => null,
/*
|--------------------------------------------------------------------------
| Drip Endpoint URL
|--------------------------------------------------------------------------
|
| Sometimes you may wish to white-label your app and not expose the AJAX
| request URLs as belonging to this package. To achieve that you can
| rename the URL used for dripping caffeine into your application.
|
| Default: 'genealabs/laravel-caffeine/drip' (string)
|
*/
'route' => 'genealabs/laravel-caffeine/drip', // Customizable end-point URL
/*
|--------------------------------------------------------------------------
| Checking for Lapsed Drips
|--------------------------------------------------------------------------
|
| If the browser is put to sleep on (for example on mobile devices or
| laptops), it will still cause an error when trying to submit the
| form. To avoid this, we force-reload the form 2 minutes prior
| to session time-out or later. Setting this setting to 0
| will disable this check if you don't want to use it.
|
| Default: 2000 (int)
|
*/
'outdated-drip-check-interval' => 2000,
/*
|--------------------------------------------------------------------------
| Use Route Middleware
|--------------------------------------------------------------------------
|
| Drips are enabled via route middleware instead of global middleware.
|
| Default: false (bool)
|
*/
'use-route-middleware' => false,
];
Only publish the config file if you need to customize it:
php artisan caffeine:publish --config
That was 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 inbrowsers.
There are two methods to prevent Caffeine for Laravel from dripping to keep thesession alive: disabling it in Blade using the meta tag method, or enablingroute-middleware mode, and then only enabling it on routes or route groups.
If you would like to prevent a certain page from caffeinating your application,then add the following meta tag:
<meta name="caffeinated" content="false">
To enable this mode, you need to publish the configuration file (see theconfiguration section above) and then set use-route-middleware
to true
. Thiswill disable the default global middleware mode (which applies it to any pagethat has the CSRF token in it across your entire application). Now you need toselectively enable Caffeine on a given route or route group using routemiddleware:
Route::any('test', 'TestController@test')->middleware('caffeinated');
Route::group(['middleware' => ['caffeinated']], function () {
Route::any('test', 'TestController@test');
})
You can still use the route middleware method and apply it globally to allroutes by editing app/Http/Kernel.php
and adding it to the web
middlewaregroup. Although you should only use this option if you have a very specific use-case that prevents you from utilizing the default global middleware option.
This will only have effect if the page includes a form. If not, the page willnot caffeinate your application anyway.
During package development I try as best as possible to embrace good design anddevelopment practices to try to ensure that this package is as good as it canbe. My checklist for package development includes:
Please observe and respect all aspects of the included Code of Conducthttps://github.com/GeneaLabs/laravel-caffeine/blob/master/CODE_OF_CONDUCT.md.
When reporting issues, please fill out the included template as completely aspossible. Incomplete issues may be ignored or closed if there is not enoughinformation included to be actionable.
Please review the Contribution Guidelines https://github.com/GeneaLabs/laravel-caffeine/blob/master/CONTRIBUTING.md.Only PRs that meet all criterium will be accepted.
We have included the awesome symfony/thanks
composer package as a devdependency. Let your OS package maintainers know you appreciate them by starringthe packages you use. Simply run composer thanks
after installing thispackage. (And not to worry, since it's a dev-dependency it won't be installed inyour live environment.)
Laravel 是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。 功能特点 1、语法更富有表现力 你知道下面这行代码里 “true” 代表什么意思么? $uri = Uri::create(‘some/uri’, array(), array(), tr
我需要空间/Laravel权限的帮助。当我试图分配它给我错误哎呀,看起来像出了问题。 错误 Connection.php第761行中的QueryExcema:SQLSTATE[23000]:完整性约束冲突:1048列role_id不能为空(SQL:插入到(,)值(9,))
Laravel 作为现在最流行的 PHP 框架,其中的知识较多,所以单独拿出来写一篇。 简述 Laravel 的生命周期 Laravel 采用了单一入口模式,应用的所有请求入口都是 public/index.php 文件。 注册类文件自动加载器 : Laravel通过 composer 进行依赖管理,无需开发者手动导入各种类文件,而由自动加载器自行导入。 创建服务容器:从 bootstrap/ap
简介 Laravel Scout 为 Eloquent 模型 全文搜索提供了简单的,基于驱动的解决方案。通过使用模型观察者,Scout 会自动同步 Eloquent 记录的搜索索引。 目前,Scout 自带一个 Algolia 驱动;不过,编写自定义驱动很简单, 你可以轻松的通过自己的搜索实现来扩展 Scout。 安装 首先,通过 Composer 包管理器来安装 Scout: composer
简介 Laravel 致力于让整个 PHP 开发体验变得愉快, 包括你的本地开发环境。 Vagrant 提供了一种简单,优雅的方式来管理和配置虚拟机。 Laravel Homestead 是一个官方预封装的 Vagrant box,它为你提供了一个完美的开发环境,而无需在本地机器安装 PHP 、Web 服务器和其他服务器软件。不用担心会搞乱你的操作系统!Vagrant boxes 是一次性的。如果
WebStack-Laravel 一个开源的网址导航网站项目,具备完整的前后台,您可以拿来制作自己的网址导航。 部署 克隆代码: git clone https://github.com/hui-ho/WebStack-Laravel.git 安装依赖: composer installphp artisan key:generate 编辑配置: cp .env.example .env ...D
百度编辑器 For Laravel 5 支持自定义路由, 默认前后台独立控制器,支持重写方法方便自己的业务逻辑处理,支持扩展图片助手(推荐使用Intervention\Image第三方包) 官网 NinJa911工作室. 疑问讨论 请在issue里new一个. 授权 此Laravel 扩展包基于MIT协议开源MIT license. 安装 1.Composer 安装 composer requir
laravel-admin是一个基于laravel的后台管理开发框架,能帮助你使用很少的时间和代码量开发出功能完备的管理后台,另外它作为一个三方包,可以和框架内其它项目并行开发,真正做到前后台开发分离。 功能: RBAC权限管理模块。 菜单管理,和权限系统结合。 模型数据表格,能快速构建数据表格,并支持多种模型关系。 模型表单以及30+种form元素组件,自动实现增、删、改功能。 支持本地和云存储