PHPackages                             mkastoun/laravel-419-handler - 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. mkastoun/laravel-419-handler

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mkastoun/laravel-419-handler
============================

Graceful handling of Laravel 419 session expired errors.

v1.1.2(1y ago)0100MITPHPPHP &gt;=8.0CI passing

Since Mar 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mkastoun/laravel-419-handler)[ Packagist](https://packagist.org/packages/mkastoun/laravel-419-handler)[ RSS](/packages/mkastoun-laravel-419-handler/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

Laravel 419 Handler
===================

[](#laravel-419-handler)

Gracefully handle `419 Page Expired` errors in Laravel using a clean, package-based trait that integrates into your `Handler.php`.

---

✨ Features
----------

[](#-features)

- Handles `TokenMismatchException` (CSRF/session expiration)
- Clean `trait`-based integration (no overriding core Laravel handlers)
- Redirects with flash messages (web)
- JSON error response (API)
- Configurable behavior

---

📦 Installation
--------------

[](#-installation)

Via Composer:

```
composer require mkastoun/laravel-419-handler
```

---

⚙️ Publish Configuration
------------------------

[](#️-publish-configuration)

```
php artisan vendor:publish --provider="Laravel419Handler\Laravel419HandlerServiceProvider" --tag=config
```

Configuration (config/laravel419.php)
-------------------------------------

[](#configuration-configlaravel419php)

```
return [
    'redirect_on_web' => '/',
    'flash_message' => 'Your session has expired. Please try again.',
    'auto_refresh_on_back' => true,
    'json_response' => [
        'message' => 'Session expired. Please try again.',
        'status' => 419,
    ],
];
```

🧩 Integration
-------------

[](#-integration)

In your `App\Exceptions\Handler.php`:

1. Import and use the trait:

```
use Laravel419Handler\Traits\HandlesTokenMismatch;
use Illuminate\Session\TokenMismatchException;

class Handler extends ExceptionHandler
{
    use HandlesTokenMismatch;

    public function render($request, Throwable $e)
    {
        if ($e instanceof TokenMismatchException) {
            return $this->handleTokenMismatch($request, $e);
        }

        return parent::render($request, $e);
    }
}
```

2. In your Blade layout, show the flash error (Optional):

```
@if(session('error'))

        {{ session('error') }}

@endif
```

🧪 Testing
---------

[](#-testing)

```
composer test
```

---

📄 License
---------

[](#-license)

MIT

---

🤝 Contributing
--------------

[](#-contributing)

PRs welcome! Please submit issues, ideas, and improvements to help others benefit from this package.

---

🧠 Why Not Middleware?
---------------------

[](#-why-not-middleware)

While catching 419s via middleware is sometimes possible, it’s not 100% reliable because `TokenMismatchException` is thrown **before** controller or middleware logic in some cases. Using a trait inside the exception handler guarantees full coverage — safely and cleanly.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance46

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

5

Last Release

402d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/67855581?v=4)[Mathieu Kastoun](/maintainers/mkastoun)[@mkastoun](https://github.com/mkastoun)

---

Top Contributors

[![mkastoun](https://avatars.githubusercontent.com/u/67855581?v=4)](https://github.com/mkastoun "mkastoun (8 commits)")

### Embed Badge

![Health badge](/badges/mkastoun-laravel-419-handler/health.svg)

```
[![Health](https://phpackages.com/badges/mkastoun-laravel-419-handler/health.svg)](https://phpackages.com/packages/mkastoun-laravel-419-handler)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M375](/packages/illuminate-redis)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
