https://github.com/devtical/laravel-drunk-on-419
Handles 419 errors gracefully by redirecting users when CSRF tokens expire.
https://github.com/devtical/laravel-drunk-on-419
419 laravel
Last synced: 10 months ago
JSON representation
Handles 419 errors gracefully by redirecting users when CSRF tokens expire.
- Host: GitHub
- URL: https://github.com/devtical/laravel-drunk-on-419
- Owner: devtical
- License: mit
- Created: 2025-01-11T03:51:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-03T03:15:06.000Z (over 1 year ago)
- Last Synced: 2025-03-03T03:17:28.876Z (over 1 year ago)
- Topics: 419, laravel
- Language: PHP
- Homepage:
- Size: 8.41 MB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Drunk on 419
[](https://packagist.org/packages/devtical/laravel-drunk-on-419)
[](https://github.com/devtical/laravel-drunk-on-419/actions/workflows/run-tests.yml)
[](https://packagist.org/packages/devtical/laravel-drunk-on-419)

Handles 419 errors gracefully by redirecting users when CSRF tokens expire.
## Installation
You can install the package via composer:
```bash
composer require devtical/laravel-drunk-on-419
```
## Usage
#### Automatic Middleware Registration
Once installed, the package automatically registers the middleware in the web group to handle CSRF token expiry errors. This means it will handle all requests in the `web` middleware group without requiring manual registration.
#### Flashing Session Data
When a CSRF token expires and a 419 error occurs, the middleware redirects the user to the previous page (if available) or a fallback URL, with an error message flashed to the session. You can display the error message in your views using the following:
```php
@session('expired')
{{ $value }}
@endsession
```
#### Publishing Language Files
You can publish the language files to customize the error message:
```bash
php artisan vendor:publish --tag=drunkon419-translations
```
This will create a language file in your application at `lang/vendor/drunkon419/session.php`. You can modify the `expired` key to suit your needs:
```php
return [
'expired' => 'Your session has expired. Please try again.',
];
```
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.