cleaniquecoders/laravel-expiry
is a Laravel package that enables expiration for user accounts and passwords with seamless middleware and event-driven support.
- Account Expiry: Middleware to check and handle expired accounts.
- Password Expiry: Middleware to enforce password expiration policies.
- Event Listeners: Automatically trigger events when accounts or passwords expire.
Install the package via Composer:
composer require cleaniquecoders/laravel-expiry
Publish and run the migration files to add the necessary expiry columns:
php artisan vendor:publish --tag=laravel-expiry-migrations
php artisan migrate
The package automatically registers the following middleware in your application:
account.expiry
: Handles account expiry checks.password.expiry
: Handles password expiry checks.
Use the middleware in your routes to enforce expiry checks:
Route::middleware(['account.expiry', 'password.expiry'])->group(function () {
Route::get('/protected-route', [SomeController::class, 'index']);
});
The package provides a configuration-driven approach to managing event listeners. By default, the following events and listeners are configured:
The configuration (config/laravel-expiry.php
) includes the following mappings:
'events' => [
\CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [
\CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class,
],
\CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [
\CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class,
],
],
The package automatically registers these events and listeners. You can modify or extend the behaviour by updating the configuration file.
For example, when a user's account or password expires:
- The
ExpiredAccount
orExpiredPassword
event is triggered. - The
LogoutOnExpired
listener handles these events by logging the user out.
To add custom listeners for these events, update the configuration file (config/laravel-expiry.php
):
'events' => [
\CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [
\App\Listeners\YourCustomListener::class,
],
\CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [
\App\Listeners\YourCustomListener::class,
],
],
With this setup, the package makes it easy to integrate custom logic for handling expiry events.
To run the test suite, use the following command:
vendor/bin/pest --testdox
The package is fully tested with PestPHP to ensure reliability.
Thank you for considering contributing to cleaniquecoders/laravel-expiry
. Contributions are welcome and appreciated!
If you find a bug, you can either:
- Submit a pull request with a failing test case.
- Create an issue describing the problem clearly with steps to reproduce it.
The package follows PSR-2 coding standards and PSR-4 autoloading.
This package is open-source software licensed under the MIT license.