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(11mo ago)099MITPHPPHP &gt;=8.0CI passing

Since Mar 26Pushed 11mo 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 1mo ago

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 65% of packages

Maintenance51

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

348d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7f78acbccc0a03303fe93f3fb60ccb67da65906ae632db87cffd67ce06196f8e?d=identicon)[mkastoun](/maintainers/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

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M686](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M157](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M211](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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