GithubHelp home page GithubHelp logo

mikebronner / laravel-caffeine Goto Github PK

View Code? Open in Web Editor NEW
901.0 25.0 84.0 526 KB

Keeping Your Laravel Forms Awake.

Home Page: https://genealabs.com/docs/laravel-caffeine/

License: MIT License

PHP 87.87% Blade 12.13%
laravel middleware package

laravel-caffeine's Introduction

Caffeine for Laravel

Travis Scrutinizer Coveralls GitHub (pre-)release Packagist

Caffeine for Laravel masthead image.

Supporting This Package

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.

We thank the following sponsors for their generosity. Please take a moment to check them out:

Goal

Prevent forms from timing out when submitting them after leaving them on-screen for a considerable amount of time. (Laravel defaults to 120 minutes, but that is configurable and could be different site-by-site.)

Implementation

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 will time-out as normal.

Reasoning

I chose this approach to keep the integrity of site-security, by avoiding the following:

  • exposing the CSRF Token on an unsecured endpoint.
  • eliminating CSRF Token validation on specific routes, or even altogether.
  • removing session-timeout on all pages.

Considerations

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. See details below for configuration and implementation of route-based middleware.

Routes

This package adds the routes under genealabs/laravel-caffeine.

Dependencies

Your project must fullfill the following:

  • Laravel 8.0 or higher
  • PHP 7.3 or higher.

Installation

composer require genealabs/laravel-caffeine

Upgrade Notes

If you have previously registered the middleware, please remove the following middleware from app/Http/Kernel.php:

// protected $middleware = [
    GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware::class,
// ];

0.6.0

This update changes the config file setting names. Please delete the published config file config/genealabs-laravel-caffeine.php if it exists, and follow the configuration instructions below.

Configuration

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

Usage

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 in browsers.

Prevent Caffeination

There are two methods to prevent Caffeine for Laravel from dripping to keep the session alive: disabling it in Blade using the meta tag method, or enabling route-middleware mode, and then only enabling it on routes or route groups.

Meta Tag Method

If you would like to prevent a certain page from caffeinating your application, then add the following meta tag:

<meta name="caffeinated" content="false">

Route Middleware Method

To enable this mode, you need to publish the configuration file (see the configuration section above) and then set use-route-middleware to true. This will disable the default global middleware mode (which applies it to any page that has the CSRF token in it across your entire application). Now you need to selectively enable Caffeine on a given route or route group using route middleware:

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 all routes by editing app/Http/Kernel.php and adding it to the web middleware group. 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 will not caffeinate your application anyway.

The Fine Print

Commitment to Quality

During package development I try as best as possible to embrace good design and development practices to try to ensure that this package is as good as it can be. My checklist for package development includes:

  • ✅ Achieve as close to 100% code coverage as possible using unit tests.
  • ✅ Eliminate any issues identified by SensioLabs Insight and Scrutinizer.
  • ✅ Be fully PSR1, PSR2, and PSR4 compliant.
  • ✅ Include comprehensive documentation in README.md.
  • ✅ Provide an up-to-date CHANGELOG.md which adheres to the format outlined at https://keepachangelog.com.
  • ✅ Have no PHPMD or PHPCS warnings throughout all code.

Contributing

Please observe and respect all aspects of the included Code of Conduct https://github.com/GeneaLabs/laravel-caffeine/blob/master/CODE_OF_CONDUCT.md.

Reporting Issues

When reporting issues, please fill out the included template as completely as possible. Incomplete issues may be ignored or closed if there is not enough information included to be actionable.

Submitting Pull Requests

Please review the Contribution Guidelines https://github.com/GeneaLabs/laravel-caffeine/blob/master/CONTRIBUTING.md. Only PRs that meet all criterium will be accepted.

❤️ Open-Source Software - Give ⭐️

We have included the awesome symfony/thanks composer package as a dev dependency. Let your OS package maintainers know you appreciate them by starring the packages you use. Simply run composer thanks after installing this package. (And not to worry, since it's a dev-dependency it won't be installed in your live environment.)

laravel-caffeine's People

Contributors

aglipanci avatar annabelka avatar cauevsilva avatar chadhobson avatar dallincoons avatar dariusiii avatar davidrendium avatar dependabot-preview[bot] avatar dragonfire1119 avatar erickbelfy avatar ericlbarnes avatar inxilpro avatar ipalaus avatar italobc avatar jbrooksuk avatar konafets avatar kristofmorva avatar laravel-shift avatar mikebronner avatar multisuperfreek avatar percymamedy avatar renolooijmans avatar rjsworking avatar sjbronner avatar symbios-zi avatar theokouzelis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-caffeine's Issues

laravel-caffeine injecting itself into Groove Widget script

I am trying to install the Groove Widget code into my project but part of the code for laravel-caffeine seems to be injected into the Groove widget code. It looks like the Groove widget creates an iFrame with a body tag and I am not sure if l-c is detecting this additional body tag and injecting code into it, breaking the widget.

Here is sample code for the GrooveHQ Widget as it is in my project

<!-- BEGIN GROOVE WIDGET CODE -->
<script id="grv-widget">
  /*<![CDATA[*/
  window.groove = window.groove || {}; groove.widget = function(){ groove._widgetQueue.push(Array.prototype.slice.call(arguments)); }; groove._widgetQueue = [];
  groove.widget('setWidgetId', 'xxxxxxxxxxxxxx');
  !function(g,r,v){var a,c,n=r.createElement("iframe");(n.frameElement||n).style.cssText="width: 0; height: 0; border: 0",n.title="",n.role="presentation",n.src="javascript:false",r.body.appendChild(n);try{a=n.contentWindow.document}catch(b){c=r.domain;var d="javascript:document.write('<head><script>document.domain=\""+c+"\";</",i="script></head><body></body>')";n.src=d+i,a=n.contentWindow.document}var s="https:"==r.location.protocol?"https://":"http://",p="http://groove-widget-production.s3.amazonaws.com".replace("http://",s);n.className="grv-widget-tag",a.open()._l=function(){c&&(this.domain=c);var t=this.createElement("script");t.type="text/javascript",t.charset="utf-8",t.async=!0,t.src=p+"/loader.js",this.body.appendChild(t)},a.write('<body onload="document._l();">'),a.close()}(window,document);
  /*]]>*/
</script>
<!-- END GROOVE WIDGET CODE -->

Here is how it renders after laravel-caffeine injects itself into the widget code

<script id="grv-widget">
    /*<![CDATA[*/
    window.groove = window.groove || {}; groove.widget = function(){ groove._widgetQueue.push(Array.prototype.slice.call(arguments)); }; groove._widgetQueue = [];
    groove.widget('setWidgetId', 'xxxxxxxxxxxxxx');
    !function(g,r,v){var a,c,n=r.createElement("iframe");(n.frameElement||n).style.cssText="width: 0; height: 0; border: 0",n.title="",n.role="presentation",n.src="javascript:false",r.body.appendChild(n);try{a=n.contentWindow.document}catch(b){c=r.domain;var d="javascript:document.write('<head><script>document.domain=\""+c+"\";</",i="script></head><body><script>setInterval(function(){var e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject('Microsoft.XMLHTTP');e.open('GET','http://v3.dev/genealabs/laravel-caffeine/drip',!0);e.setRequestHeader('X-Requested-With','XMLHttpRequest');e.send();}, 300000);</script>
')";n.src=d+i,a=n.contentWindow.document}var s="https:"==r.location.protocol?"https://":"http://",p="http://groove-widget-production.s3.amazonaws.com".replace("http://",s);n.className="grv-widget-tag",a.open()._l=function(){c&&(this.domain=c);var t=this.createElement("script");t.type="text/javascript",t.charset="utf-8",t.async=!0,t.src=p+"/loader.js",this.body.appendChild(t)},a.write(''),a.close()}(window,document);
    /*]]>*/
<!-- END GROOVE WIDGET CODE -->

I was wondering if there are any solutions or workarounds to get them playing well together.

Undefined index: middleware

System: Laravel 5.2.20 / PHP 7.0.2

With the latest commit, I'm getting the following error:

screen shot 2016-02-20 at 17 04 33

It's solved by changing the routes.php file to:

if (isset(Route::getMiddleware()['web'])) {

Having drip interval relative to session ?

Hi,

Not an issue but a suggestion : what about setting by default the drip interval in relation of the session time configured ?

Maybe config("session.lifetime")601000/2 on line 27 in the MiddleWare ?

Laravel 5.2 middleware issue

Ran into this error after upgrading to Laravel 5.2:

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Interface 'Illuminate\Contracts\Routing\Middleware' not found"

Stacktrace:
#35 Symfony\Component\Debug\Exception\FatalErrorException in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/genealabs/laravel-caffeine/src/Http/Middleware/LaravelCaffeineDripMiddleware.php:7
#34 Symfony\Component\Debug\Exception\FatalErrorException:__construct in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:133
#33 Illuminate\Foundation\Bootstrap\HandleExceptions:fatalExceptionFromError in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:118
#32 Illuminate\Foundation\Bootstrap\HandleExceptions:handleShutdown in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:0
#31  in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/composer/ClassLoader.php:412
#30 Composer\Autoload\includeFile in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/composer/ClassLoader.php:301
#29 Composer\Autoload\ClassLoader:loadClass in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Container/Container.php:736
#28 spl_autoload_call in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Container/Container.php:736
#27 ReflectionClass:__construct in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Container/Container.php:736
#26 Illuminate\Container\Container:build in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Container/Container.php:631
#25 Illuminate\Container\Container:make in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:674
#24 Illuminate\Foundation\Application:make in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:123
#23 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:64
#22 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#21 call_user_func_array:{/home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#20 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#19 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#18 call_user_func_array:{/home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#17 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:62
#16 Illuminate\Session\Middleware\StartSession:handle in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#15 call_user_func_array:{/home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#14 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#13 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#12 call_user_func_array:{/home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#11 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59
#10 Illuminate\Cookie\Middleware\EncryptCookies:handle in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#9 call_user_func_array:{/home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#8 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:44
#7 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#6 call_user_func_array:{/home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:124
#5 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#4 call_user_func:{/home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103} in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
#3 Illuminate\Pipeline\Pipeline:then in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:132
#2 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /home/vagrant/PhpstormProjects/fvrs-version-2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:99
#1 Illuminate\Foundation\Http\Kernel:handle in /home/vagrant/PhpstormProjects/fvrs-version-2/public/index.php:54
#0 {main} in /home/vagrant/PhpstormProjects/fvrs-version-2/public/index.php:0

Ignore L5.3 Logout Form

Laravel 5.3 changed its logout route to be a post, and uses a form in the menu to do so. This has the unintended consequence of keeping the session alive indefinitely, something we don't want.

I would like to explore options to not keep the session alive, yet remain user-friendly. Not sure how feasable this is:

  • Do not keep session alive if only the logout form and no other form is rendered.

Class web does not exist

When run route /genealabs/laravel-caffeine/drip
it return error 500 with ReflectionException in Container.php line 741:
Class web does not exist

ServiceProvider path and middlewareGroupExists() error

Right after the installation of 5.3, I got "ServiceProvider not found" error.

Class 'GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider' not found

I guess service provider path and file name has been changed to...

GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService::class,

right?

But, when I change the path and file name, I get type error.

Type error: Return value of GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService::middlewareGroupExists() must be of the type boolean, null returned

Does it Work for L5.4?

Environment

  • PHP Version: 7
  • Laravel Version: 5.4
  • LaravelCaffeine Version: 0.3.12

Question

I just installed for a 5.4 laravel instalation running on forge. It doenst trace any errors. i dont know if it works yet. I openen a form and have being waiting for over 2 hours and it looks it works. But have you test it out? so i can push it to production?

Meta tag token doesn't appear to be working

Hi Mike,

There appears to be an issue when I set a meta tag with the content of {{ csrf_token() }}. I get the usual error of:

Symfony \ Component \ HttpKernel \ Exception \ BadRequestHttpException
CSRF token validation failed.

My meta tag is:

<meta name="csrf-token" content="{{ csrf_token() }}">

and I register the meta tag in my javascript:

Vue.http.headers.common['X-CSRF-TOKEN'] = $("meta[name='csrf-token']").attr('content');

Needless to say, it absolutely works fine until the token times out.

All Views are rendered twice

This is because calling $content->render(); in LaravelCaffeineDripMiddleware.php on line 28.
I noticed this behaviour because in one of my Views I use Session::pull(). The data are pulled during the first rendering and of course no longer available when the View is rendered the second time (and delivered to the client).

Any suggestions to avoid this?

caffeine vs session.lifetime

Would you be able to explain what the difference between just upping the value of lifetime is and what caffeine provides? One of your points per the doc is:

removing session-timeout on all pages.

Can't that essentially be achieved by setting lifetime to a very high value?

Problems with the installation

working with laravel 5.2.45

installed via composer require genealabs/laravel-caffeine:~0.3.11

inserted in the config/app file

GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService::class,

but laravel throws

Class 'GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService' not found

error.

g patrick

in_array() expects paramter 2 to be array, string given

Experiencing this issue after the latest updated. Laravel 5.2:

exception 'ErrorException' with message 'in_array() expects parameter 2 to be array, string given' 
in /home/vagrant/fvrs-v2/vendor/genealabs/laravel-caffeine/src/Http/routes.php:18
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'in_array() expe...', '/home/vagrant/f...', 18, Array)
#1 /home/vagrant/fvrs-v2/vendor/genealabs/laravel-caffeine/src/Http/routes.php(18): in_array('web', 'web')
#2 /home/vagrant/fvrs-v2/vendor/genealabs/laravel-caffeine/src/Http/routes.php(5): hasWebMiddleware()
#3 /home/vagrant/fvrs-v2/vendor/genealabs/laravel-caffeine/src/LaravelCaffeineServiceProvider.php(12): require('/home/vagrant/f...')
#4 [internal function]: GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider->boot()
#5 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#6 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->call(Array)
#7 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(717): Illuminate\Foundation\Application->bootProvider(Object(GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider))
#8 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider), 20)
#9 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(718): array_walk(Array, Object(Closure))
#10 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
#11 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#12 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(232): Illuminate\Foundation\Application->bootstrapWith(Array)
#13 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(127): Illuminate\Foundation\Http\Kernel->bootstrap()
#14 /home/vagrant/fvrs-v2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#15 /home/vagrant/fvrs-v2/public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#16 {main}

ReflectionException: Class web does not exist

In a fresh laravel 5.2, caffeine works. But on an existing laravel (from 5.1 to 5.2), it throws this exception:

ReflectionException: Class web does not exist 

This commit 2b8a220, added a route group with web middleware. But I think the web middleware is optional and may be removed (it's not in vendor but in app). So Caffeine has a dependency about an optional middleware (it does not exists on migration and may not exists in modified fresh install).

Anyway, thanks for this package :)

syntax errors in LaravelCaffeineService.php

Expected Behavior

Actual Behavior

I have just installed laravel-caffeine and there seems to be multiple syntax errors on lines 28, 33 and 38.

Environment

  • PHP Version: 7.0
  • Laravel Version: 5.4
  • LaravelCaffeine Version:latest

Stack Trace

Backport configurable routes to version 0.2.x

From @larsbo:

Another problem with the hard-coded route is that it doesn't work for laravel installations in subdirectories because the route starts with a /.

What about adding the configurable route to the 0.2.x branch for laravel 5.1 users?

Causes PHPUnit errors - Cannot redeclare hasWebMiddleware()

With the package installed I get the following errors when I run vendor/bin/phpunit in my Laravel v5.2.20 app:

.PHP Fatal error:  Cannot redeclare hasWebMiddleware() (previously declared in /home/vagrant/Code/MyProject/vendor/genealabs/laravel-caffeine/src/Http/routes.php:13) in /home/vagrant/Code/MyProject/vendor/genealabs/laravel-caffeine/src/Http/routes.php on line 28
PHP Stack trace:
PHP   1. {main}() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:47
PHP   3. PHPUnit_TextUI_Command->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:100
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:149
PHP   5. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
PHP   6. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   7. PHPUnit_Framework_TestCase->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   8. PHPUnit_Framework_TestResult->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
PHP   9. PHPUnit_Framework_TestCase->runBare() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
PHP  10. Illuminate\Foundation\Testing\TestCase->setUp() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:764
PHP  11. Illuminate\Foundation\Testing\TestCase->refreshApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:64
PHP  12. TestCase->createApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:85
PHP  13. Illuminate\Foundation\Console\Kernel->bootstrap() /home/vagrant/Code/MyProject/tests/TestCase.php:23
PHP  14. Illuminate\Foundation\Application->bootstrapWith() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:208
PHP  15. Illuminate\Foundation\Bootstrap\BootProviders->bootstrap() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:203
PHP  16. Illuminate\Foundation\Application->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
PHP  17. array_walk() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
PHP  18. Illuminate\Foundation\Application->Illuminate\Foundation\{closure}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
PHP  19. Illuminate\Foundation\Application->bootProvider() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:717
PHP  20. Illuminate\Container\Container->call() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:734
PHP  21. call_user_func_array:{/home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
PHP  22. GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:752
Stack trace:
#0 /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /home/vagrant/Code/Health in /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 752
PHP Stack trace:
PHP   1. {main}() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:47
PHP   3. PHPUnit_TextUI_Command->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:100
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:149
PHP   5. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
PHP   6. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   7. PHPUnit_Framework_TestCase->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   8. PHPUnit_Framework_TestResult->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
PHP   9. PHPUnit_Framework_TestCase->runBare() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
PHP  10. Illuminate\Foundation\Testing\TestCase->setUp() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:764
PHP  11. Illuminate\Foundation\Testing\TestCase->refreshApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:64
PHP  12. TestCase->createApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:85
PHP  13. Illuminate\Foundation\Console\Kernel->bootstrap() /home/vagrant/Code/MyProject/tests/TestCase.php:23
PHP  14. Illuminate\Foundation\Application->bootstrapWith() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:208
PHP  15. Illuminate\Foundation\Bootstrap\BootProviders->bootstrap() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:203
PHP  16. Illuminate\Foundation\Application->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
PHP  17. array_walk() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
PHP  18. Illuminate\Foundation\Application->Illuminate\Foundation\{closure}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
PHP  19. Illuminate\Foundation\Application->bootProvider() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:717
PHP  20. Illuminate\Container\Container->call() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:734
PHP  21. call_user_func_array:{/home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
PHP  22. GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507

Fatal error: Cannot redeclare hasWebMiddleware() (previously declared in /home/vagrant/Code/MyProject/vendor/genealabs/laravel-caffeine/src/Http/routes.php:13) in /home/vagrant/Code/MyProject/vendor/genealabs/laravel-caffeine/src/Http/routes.php on line 28

Call Stack:
    0.0003     353920   1. {main}() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:0
    0.3202    1423064   2. PHPUnit_TextUI_Command::main() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:47
    0.3202    1423176   3. PHPUnit_TextUI_Command->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:100
    2.5127    4533856   4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:149
    2.5826    4638848   5. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
    2.5843    4645296   6. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
    6.3418   13871320   7. PHPUnit_Framework_TestCase->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
    6.3418   13871320   8. PHPUnit_Framework_TestResult->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
    6.3418   13871320   9. PHPUnit_Framework_TestCase->runBare() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
    6.3419   13887848  10. Illuminate\Foundation\Testing\TestCase->setUp() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:764
    6.3419   13887848  11. Illuminate\Foundation\Testing\TestCase->refreshApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:64
    6.3419   13887848  12. TestCase->createApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:85
    6.3434   13907600  13. Illuminate\Foundation\Console\Kernel->bootstrap() /home/vagrant/Code/MyProject/tests/TestCase.php:23
    6.3434   13907600  14. Illuminate\Foundation\Application->bootstrapWith() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:208
    6.5850   14038056  15. Illuminate\Foundation\Bootstrap\BootProviders->bootstrap() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:203
    6.5850   14038056  16. Illuminate\Foundation\Application->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
    6.5850   14038400  17. array_walk() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
    6.6323   14114144  18. Illuminate\Foundation\Application->Illuminate\Foundation\{closure}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
    6.6323   14114144  19. Illuminate\Foundation\Application->bootProvider() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:717
    6.6324   14114520  20. Illuminate\Container\Container->call() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:734
    6.6324   14114632  21. call_user_func_array:{/home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
    6.6324   14114696  22. GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507


Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 752

Call Stack:
    0.0003     353920   1. {main}() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:0
    0.3202    1423064   2. PHPUnit_TextUI_Command::main() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:47
    0.3202    1423176   3. PHPUnit_TextUI_Command->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:100
    2.5127    4533856   4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:149
    2.5826    4638848   5. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
    2.5843    4645296   6. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
    6.3418   13871320   7. PHPUnit_Framework_TestCase->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
    6.3418   13871320   8. PHPUnit_Framework_TestResult->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
    6.3418   13871320   9. PHPUnit_Framework_TestCase->runBare() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
    6.3419   13887848  10. Illuminate\Foundation\Testing\TestCase->setUp() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:764
    6.3419   13887848  11. Illuminate\Foundation\Testing\TestCase->refreshApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:64
    6.3419   13887848  12. TestCase->createApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:85
    6.3434   13907600  13. Illuminate\Foundation\Console\Kernel->bootstrap() /home/vagrant/Code/MyProject/tests/TestCase.php:23
    6.3434   13907600  14. Illuminate\Foundation\Application->bootstrapWith() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:208
    6.5850   14038056  15. Illuminate\Foundation\Bootstrap\BootProviders->bootstrap() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:203
    6.5850   14038056  16. Illuminate\Foundation\Application->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
    6.5850   14038400  17. array_walk() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
    6.6323   14114144  18. Illuminate\Foundation\Application->Illuminate\Foundation\{closure}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
    6.6323   14114144  19. Illuminate\Foundation\Application->bootProvider() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:717
    6.6324   14114520  20. Illuminate\Container\Container->call() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:734
    6.6324   14114632  21. call_user_func_array:{/home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
    6.6324   14114696  22. GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 752

Call Stack:
    0.0003     353920   1. {main}() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:0
    0.3202    1423064   2. PHPUnit_TextUI_Command::main() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/phpunit:47
    0.3202    1423176   3. PHPUnit_TextUI_Command->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:100
    2.5127    4533856   4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/Command.php:149
    2.5826    4638848   5. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
    2.5843    4645296   6. PHPUnit_Framework_TestSuite->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
    6.3418   13871320   7. PHPUnit_Framework_TestCase->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
    6.3418   13871320   8. PHPUnit_Framework_TestResult->run() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
    6.3418   13871320   9. PHPUnit_Framework_TestCase->runBare() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
    6.3419   13887848  10. Illuminate\Foundation\Testing\TestCase->setUp() /home/vagrant/Code/MyProject/vendor/phpunit/phpunit/src/Framework/TestCase.php:764
    6.3419   13887848  11. Illuminate\Foundation\Testing\TestCase->refreshApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:64
    6.3419   13887848  12. TestCase->createApplication() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:85
    6.3434   13907600  13. Illuminate\Foundation\Console\Kernel->bootstrap() /home/vagrant/Code/MyProject/tests/TestCase.php:23
    6.3434   13907600  14. Illuminate\Foundation\Application->bootstrapWith() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:208
    6.5850   14038056  15. Illuminate\Foundation\Bootstrap\BootProviders->bootstrap() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:203
    6.5850   14038056  16. Illuminate\Foundation\Application->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
    6.5850   14038400  17. array_walk() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
    6.6323   14114144  18. Illuminate\Foundation\Application->Illuminate\Foundation\{closure}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:718
    6.6323   14114144  19. Illuminate\Foundation\Application->bootProvider() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:717
    6.6324   14114520  20. Illuminate\Container\Container->call() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:734
    6.6324   14114632  21. call_user_func_array:{/home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507}() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
    6.6324   14114696  22. GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider->boot() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
    6.6470   14155696  23. Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:0
    6.6604   14192432  24. Illuminate\Foundation\Bootstrap\HandleExceptions->handleException() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:118
    6.6604   14192432  25. Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:79
    6.6604   14192432  26. Illuminate\Foundation\Application->make() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:154
    6.6604   14192488  27. Illuminate\Container\Container->make() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:674
    6.6604   14192488  28. Illuminate\Container\Container->build() /home/vagrant/Code/MyProject/vendor/laravel/framework/src/Illuminate/Container/Container.php:633§

url() function in the config file breaks artisan

The url function inside the generated config file breaks the artisan command.

Laravel Framework version 5.1.31 (LTS)

Stacktrace:

Catchable fatal error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in /Users/xxx/Documents/xxx/xxx/xxx/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 62 and defined in /Users/xxx/Documents/xxx/xxx/xxx/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 102

Call Stack:
0.2623 3296608 8. url() /home/vagrant/xxx/xxx/xxx/config/genealabs-laravel-caffeine.php:5

Exposing the CSRF Token on an unsecured endpoint

Hi Mike,

Firstly I'm a big fan of the package and many thanks for your work

I just wanted to test some logic with regards to exposing the CSRF token on an unsecured endpoint. I'm using VueJS alongside Laravel to create an application and I like to use Laravel to generate a token in the <script> section of my <head> tags. This is of course subjected to token mismatch exceptions when the CSRF times out. I'm ideally trying to find a solution whereby I can keep those tokens refreshed and the most simplest would be to hit a route which serves up the CSRF token.

My question though, is do you believe there are any security issues with having a route which just serves CSRF tokens?

Feature request: specify specific routes for session preservation

One problem I ran into is that my app has many forms throughout which has the effect of preserving a session indefinitely. I would like to be able to, in the configuration, specify pages in which drip can be applied to. I will likely do a pull request for this in the next few weeks. Cheers!

not working for X-CSRF-TOKEN request header

Hi,

does this package also work for ajax request? its currently not working for me. i know it says it works for any page has _token, is ajax request included?

i did as laravel doc suggests:

<meta name="csrf-token" content="{{ csrf_token() }}">

$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
});

update: i checked LaravelCafineDripMiddleware.php, and outputed $content. it turns out that the response content from my server is array instead of string since its not returning a view file. also it seems that the middleware is called twice. the first one returns content as string, the second one returns array.

Getting TokenMismatchException after laravel session lifetime even after 0.3.11 caffeine version.

Issue

Hello. I'm getting TokenMismatchException after Laravel session lifetime, just like closed issue #22. I did the same test as ivanvermeyen did: I set the session lifetime to 3 minutes and caffeine drips to 1 minute. I've checked the chrome network tab and the drips are being sent just like they should be. After 3 minutes (or 3 drips) I submit the form and then I get the TokenMismatchException.
I also noticed one thing: When I did the same test as ivanvermeyen, I had to publish the config file and customize it. After that I'm getting this error when I run an artisan command:

PHP Catchable fatal error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given

When I delete the config file, I don't get this error anymore.

I don't know if it has something to do with the TokenMismatchException error, but I think it's a relevant issue.

My enviroment:

Laravel Version: 5.2.45
Laravel Caffeine Package Version: 0.3.11
PHP Version: 5.6.22

call url() helper in config file.

due to default $domain always 'null'
$domain = config('genealabs-laravel-caffeine.domain', url('/'));

and you have to set
"domain" => url('/')

will cause the artisan error like:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\H
ttp\Request, null given, called in /..../vendor/laravel/framewo
rk/src/Illuminate/Routing/RoutingServiceProvider.php on line 64

do this for fix the error.

return [
'dripIntervalInMilliSeconds' => 300000, // every 5 minutes
'domain' => PHP_SAPI === 'cli' ? null : url('/'), // defaults to url('/')
'route' => 'genealabs/laravel-caffeine/drip', // can be customized
];

Laravel 5.4

Can't get it intalled in Laravel 5.2

After installation and add its Service Provider to my config/app.php
GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService::class,

An error displayed:
FatalErrorException in ProviderRepository.php line 146: Class 'GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineServiceProvider' not found

External file vs inline script

Javascript code here is very small, so it's a shame that we need whole additional http-request to get it.
In terms of client performance it would be better to inline this script, but I don't know how it will affect server-side performance. I have a feeling that it would add less than a millisecond or so, but can't figure out a way to test this assumption reliably.
Another approach would be just add async attribute to a script tag, so it won't affect page loading.

Support for laravel 5.5

Expected Behavior

Acutal Behavior

genealabs/laravel-caffeine 0.4.2 requires illuminate/support 5.1.* || 5.3.* || 5.4.* -> satisfiable by laravel/framework[v5.4.36], illuminate/support[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9].

Environment

  • PHP Version:
  • Laravel Version:
  • LaravelCaffeine Version:

Stack Trace

Get rid of the middleware

Just out of curiosity, why does there need to be a middleware? Can't there just be one JavaScript file you include which will check the HTML on ready for a <meta> or <input> tag with token?

I personally don't like having too many intercepting middlewares altering the output etc, would much prefer a tiny bit of vanilla js included in each page checking a few tags.

Configurable route

Why didn't you incorporate the configurable route as proposed in #9? This is really a huge bummer for me and makes me fork your package for just this small change.

Still getting TokenMismatchException after Laravel session lifetime

Hi

When I leave a form open for a while, I still get a TokenMismatchException.
I'm using Laravel 5.2.

For testing I've set the session lifetime in config/session.php to 3 minutes and the drip interval to 1 min (60000ms). The drip route is being called every minute as it should (no errors in the Chrome network tab).

After the first drip I can still send the form, but after 3 drips or minutes I get the Token exception.

TokenMismatchException in VerifyCsrfToken.php line 67:

Seems the session isn't actually being refreshed?

Unusual laravel directory structure (or .htaccess) messes up routing

The url utilized by the middleware is using a path that assumes routing paths for laravel are not changed via .htaccess or other means. This causes the drip logic to not find the controller. The solution is to use the url function to make sure the path is correct.

My fix:
Replace line 32 of LaravelCaffeineDripMiddleware.php with the following:

$content = str_replace('</body>', "<script>setInterval(function(){var e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject('Microsoft.XMLHTTP');e.open('GET','".url('/genealabs/laravel-caffeine/drip')."',!0),e.send()}," . config('genealabs-laravel-caffeine.dripIntervalInMilliSeconds', 300000) . ");</script></body>", $content);

https not http for the dripper

hi,

i want to know how to force the caffeine dripper to use a https url instead of a http? is there a way to add a setting FORCE_HTTPS?

kind regards

Andy

URL not getting hit properly

I've got a form at the following URL:

http://localhost/myproject/public/report/tokenstring

If I leave the page open for the javascript to fire I get the following in my console:

GET http://localhost/genealabs/laravel-caffeine/drip 404 (Not Found)

Am I doing something wrong? If not, is there anyway to modify the URL? Or, could you possibly make the route named:

Route::get('genealabs/laravel-caffeine/drip', [
    'as'   => 'genealabs.laravel-caffeine.drip',
    'uses' => LaravelCaffeineController::class . '@drip']
);

and reference the named route in the middleware file:

$content = str_replace('</body>', 
    "<script>setInterval(function(){var e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject('Microsoft.XMLHTTP');e.open('GET','" 
        . route('genealabs.laravel-caffeine.drip') 
        . "',!0),e.send()}," 
        . config('genealabs-laravel-caffeine.dripIntervalInMilliSeconds', 300000) 
        . ");</script></body>", $content);

Any ideas? Thank you.

I need help

Expected Behavior

Acutal Behavior

Environment

  • PHP : 7.0
  • Laravel : 5.5
  • LaravelCaffeine :0.5

Stack Trace

我安装了他 但是我不知道无法使用他 比如我要创建新的模块时如何使用?
使用composer安装后 是否还需要进行其他操作?

I installed him, but I didn't know I couldn't use him. For example, how do I use the new module when I create it?
Do you need any additional operations after using the composer installation?

404 error on drip

I believe it may be related to #10

I just installed this on Laravel 5.2 and configured it according to the instructions on the main page. I left a page up for a while and it gave me a 404 error when trying to call http://mydomain/genealabs/laravel-caffeine/drip

Visiting the url also gives 404.

Could perhaps adding the url to the routes.php file fix this issue?

Default 'genealabs/laravel-caffeine/drip' route doesn't work

Hello,
I installed Caffeine 0.4.1 on Laravel 5.3: to test, I setup session.lifetime = 1 (minute) and dripIntervalInMilliSeconds = 30000 (30 seconds); so, after one or more minute, I should be able to work on my form 'cause of Caffeine

Instead, I get a TokenMismatchException
Giving some try, I changed Caffeine route parameter to a known one (i.e. '/') and wow, I don't get the TokenMismatchException anymore

Reverting to default Caffeine route and looking at my route list (php artisan route:list) I see the genealabs/laravel-caffeine/drip one, but It's not under the web middleware: I suspect that this is the problem, am I right? Any fix, please?

Thanks

Error code 255 in composer

Hi,

Upon submiting vendor:publish as proposed, in the manual, I get a composer error code 255, on fresh new install on Laravel 5.2.

Generating autoload files

Illuminate\Foundation\ComposerScripts::postInstall
php artisan optimize
Script php artisan optimize handling the post-install-cmd event returned with error code 255.

Please advice,

Laravel 5.3 Not Compatible

Upon installing laravel caffeine, laravel fails to find the package/service provider.

Composer.json has the correct entry -- "genealabs/laravel-caffeine": "^0.4.1"

Application service provider in config/app has been added - GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider::class,

Yet artisan throws the following error..

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider' not found

Correct namespace to Caffine in readme for Laravel 5.3?

Issue

I get "Class 'GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService' not found" if I follow the installation instructions on the front page.

Found an old github issue regarding problems with Laravel 5.2 and changed to GeneaLabs\LaravelCaffeine\LaravelCaffeineServiceProvider::class and I get passed the installation. Which one is the correct one for Laravel 5.3, or will there be any problems?

Environment

Laravel Version: 5.3.29
Laravel Caffeine Package Version: 0.3.12
PHP Version: 7.1

Am I do it wrong?

I set the session life time to one minute to test it out, my app is SPA with vuejs so instead of using laravel caffeine middleware I use following code to send drip:

setInterval(function () {
     Vue.http.get('/api/drip');
 }, 10000);

I define a new drip route like so:

$router->get('api/drip', '\GeneaLabs\LaravelCaffeine\Http\Controllers\LaravelCaffeineController@drip');

I see that in network tabs it sends the drip every 10 seconds, I leave the page open for a while after filled the form and after few minutes hit the submit button and I still get token mismatch exception. Am I missing something?

Working with Content Security Policy

Greetings,

I am implementing CSP (content security policy) within my project and realized the policy is blocking the caffeine script from running. I could add 'unsafe-eval' but wouldn't this open up the possibility of XSS attacks (ref: http://stackoverflow.com/questions/8502307/chrome-18-how-to-allow-inline-scripting-with-a-content-security-policy)? I've attached 3 images (1st is the CSP, 2nd is the error message, 3rd is the script inline). What I have done with my other scripts is put them in a separate .js file and include them in the header.

One idea might be to move the script into a .js file then add a script src = "caffeine.js" on the pages needing this? Thoughts?
csp1
csp2
csp3

v0.3.2 preg_match error

I am getting this error with the v0.3.2

ErrorException in LaravelCaffeineDripMiddleware.php line 32:
preg_match(): Delimiter must not be alphanumeric or backslash

v0.3.1 works fine

Add warning session is expiring

This package is focused around always keeping forms alive, a bit of a security problem imo that's why the whole expiry thing is default in Laravel.

It would be nice to have an option where the user is prompted (via a model alert) when the session is about to expire and give them a button to stay active (essentially sending the 'drip'). This is a similar same way the banking industry handle form/session expiration.

The way the alert is shown to the user of course will be subjective and need to be styled per app, but if caffeine made it relatively generic and exposed some options or api of events to easily show a custom alert it would be nice.

LaravelCaffeine.start({
    alertText: 'Your session is about to expire.',
    btnText: 'Click to Continue'
});

LaravelCaffeine.expiring(function(drip) {
    // Show custom model and call 'drip' if button was pressed.
});

Routes completely broken after uninstall

Laravel doesn't seem to be using any routes in /routes anymore, everything returns error 404 not found after I removed this.

config/app.php has been updated accordingly but nothing seem to fix this.

Domain url('/') breaks artisan optimize

The domain => url('/') setting is breaking Laravel 5.2 artisan command.

The website works, but the artisan command crashes with a routing error.

PHP Catchable fatal error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in /home/vagrant/Code/salunet/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 62 and defined in /home/vagrant/Code/salunet/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 103

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.