mkastoun/laravel-419-handler
Composer 安装命令:
composer require mkastoun/laravel-419-handler
包简介
Graceful handling of Laravel 419 session expired errors.
README 文档
README
Gracefully handle 419 Page Expired errors in Laravel using a clean, package-based trait that integrates into your Handler.php.
✨ 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
Via Composer:
composer require mkastoun/laravel-419-handler
⚙️ Publish Configuration
php artisan vendor:publish --provider="Laravel419Handler\Laravel419HandlerServiceProvider" --tag=config
Configuration (config/laravel419.php)
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
In your App\Exceptions\Handler.php:
- 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); } }
- In your Blade layout, show the flash error (Optional):
@if(session('error')) <div class="alert alert-danger"> {{ session('error') }} </div> @endif
🧪 Testing
composer test
📄 License
MIT
🤝 Contributing
PRs welcome! Please submit issues, ideas, and improvements to help others benefit from this package.
🧠 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.
mkastoun/laravel-419-handler 适用场景与选型建议
mkastoun/laravel-419-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 100 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mkastoun/laravel-419-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mkastoun/laravel-419-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 100
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-26