PHPackages                             darkghosthunter/larapoke - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. darkghosthunter/larapoke

Abandoned → [laragear/poke](/?search=laragear%2Fpoke)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

darkghosthunter/larapoke
========================

Keep your forms alive, avoid TokenMismatchException by gently poking your Laravel app

v5.1.1(4y ago)43132.9k↓66.7%2MITPHPPHP &gt;=7.4

Since Dec 24Pushed 4y ago3 watchersCompare

[ Source](https://github.com/DarkGhostHunter/Larapoke)[ Packagist](https://packagist.org/packages/darkghosthunter/larapoke)[ Fund](https://paypal.me/darkghosthunter)[ Fund](https://ko-fi.com/DarkGhostHunter)[ RSS](/packages/darkghosthunter-larapoke/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (19)Used By (0)

Package superseeded by [Laragear/Poke](https://github.com/Laragear/Poke)
========================================================================

[](#package-superseeded-by-laragearpoke)

---

Larapoke
========

[](#larapoke)

Keep your forms alive, avoid `TokenMismatchException` by gently poking your Laravel app.

Requirements
------------

[](#requirements)

- PHP 7.4, 8.0 or later.
- Laravel 7.x, 8.x or later.

> For older versions support, consider helping by sponsoring or donating.

Installation
------------

[](#installation)

Require this package into your project using Composer:

```
composer require darkghosthunter/larapoke
```

How does it work?
-----------------

[](#how-does-it-work)

Larapoke pokes your App with an HTTP `HEAD` request to the `/poke` route at given intervals. In return, while your application renews the session lifetime, it sends an `HTTP 204` status code, which is an OK Response without body.

This amounts to **barely 800 bytes sent!**

### Automatic Reloading on CSRF token expiration

[](#automatic-reloading-on-csrf-token-expiration)

Larapoke script will detect if the CSRF session token is expired based on the last successful poke, and forcefully reload the page if there is Internet connection.

This is done by detecting [when the browser or tab becomes active](https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API), or [when the device user becomes online again](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine).

This is handy in situations when the user laptop is put to sleep, or the phone loses signal. Because the session may expire during these moments, when the browser wakes up or the phone becomes online, the page is reloaded to get the new CSRF token.

Usage
-----

[](#usage)

There are three ways to turn on Larapoke in your app.

- `auto` (easy hands-off default)
- `middleware`
- `manual`

You can change the default mode using your environment file:

```
LARAPOKE_MODE=auto
```

### `auto`

[](#auto)

Just install this package and *look at it go*. This will push a global middleware that will look into all your Responses content where:

- the content is HTML,
- an input where `csrf` token is present,
- or the meta tag `csrf-token`, are present.

If there is any case-insensitive match, this will inject the Larapoke script in charge to keep the forms alive just before the `` tag.

This mode won't inject the script on no-successful responses (anything not HTTP 2xx), like on errors or redirection.

> It's recommended to use the other modes if your application has many routes or Responses with a lot of text.

### `middleware`

[](#middleware)

This will disable the global middleware, allowing you to use the `larapoke` middleware only in the routes you explicitly decide.

```
