Skip to content

Commit d45a207

Browse files
committed
Update README
1 parent 9facb38 commit d45a207

File tree

1 file changed

+86
-26
lines changed

1 file changed

+86
-26
lines changed

README.md

Lines changed: 86 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,131 @@
1-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/cleaniquecoders/laravel-expiry.svg?style=flat-square)](https://packagist.org/packages/cleaniquecoders/laravel-expiry) [![PHPStan](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/phpstan.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/phpstan.yml) [![run-tests](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/run-tests.yml) [![Fix PHP code style issues](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/fix-styling.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/fix-styling.yml) [![Total Downloads](https://img.shields.io/packagist/dt/cleaniquecoders/laravel-expiry.svg?style=flat-square)](https://packagist.org/packages/cleaniquecoders/laravel-expiry)
1+
# Laravel Expiry
22

3-
## Laravel Expiry
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/cleaniquecoders/laravel-expiry.svg?style=flat-square)](https://packagist.org/packages/cleaniquecoders/laravel-expiry) [![PHPStan](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/phpstan.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/phpstan.yml) [![Run Tests](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/run-tests.yml) [![Fix PHP Code Style Issues](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/fix-styling.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-expiry/actions/workflows/fix-styling.yml) [![Total Downloads](https://img.shields.io/packagist/dt/cleaniquecoders/laravel-expiry.svg?style=flat-square)](https://packagist.org/packages/cleaniquecoders/laravel-expiry)
44

5-
Enable expiry on user's account and user's password.
5+
`cleaniquecoders/laravel-expiry` is a Laravel package that enables expiration for user accounts and passwords with seamless middleware and event-driven support.
6+
7+
---
8+
9+
## Features
10+
11+
- **Account Expiry**: Middleware to check and handle expired accounts.
12+
- **Password Expiry**: Middleware to enforce password expiration policies.
13+
- **Event Listeners**: Automatically trigger events when accounts or passwords expire.
14+
15+
---
616

717
## Installation
818

9-
In order to install `cleaniquecoders/laravel-expiry` in your Laravel project, just run the *composer require* command from your terminal:
19+
Install the package via Composer:
1020

1121
```bash
1222
composer require cleaniquecoders/laravel-expiry
1323
```
1424

15-
Then publish and run the migration files:
25+
Publish and run the migration files to add the necessary expiry columns:
1626

1727
```bash
1828
php artisan vendor:publish --tag=laravel-expiry-migrations
1929
php artisan migrate
2030
```
2131

22-
Register route middlewares in `app/Http/Kernel.php`:
32+
### Middleware Registration
33+
34+
The package automatically registers the following middleware in your application:
35+
36+
- **`account.expiry`**: Handles account expiry checks.
37+
- **`password.expiry`**: Handles password expiry checks.
38+
39+
---
40+
41+
## Usage
42+
43+
### Apply Middleware
44+
45+
Use the middleware in your routes to enforce expiry checks:
2346

2447
```php
25-
'account.expiry' => \CleaniqueCoders\LaravelExpiry\Http\Middleware\AccountExpiry::class,
26-
'password.expiry' => \CleaniqueCoders\LaravelExpiry\Http\Middleware\PasswordExpiry::class,
48+
Route::middleware(['account.expiry', 'password.expiry'])->group(function () {
49+
Route::get('/protected-route', [SomeController::class, 'index']);
50+
});
2751
```
2852

29-
## Usage
53+
### Event Listeners
3054

31-
Now you may use the middleware in your application:
55+
The package provides a configuration-driven approach to managing event listeners. By default, the following events and listeners are configured:
56+
57+
#### Default Event-to-Listener Mapping
58+
59+
The configuration (`config/laravel-expiry.php`) includes the following mappings:
3260

3361
```php
34-
Route::middleware(['account.expiry', 'password.expiry'])
35-
->get('/somewhere-not-expired');
62+
'events' => [
63+
\CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [
64+
\CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class,
65+
],
66+
\CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [
67+
\CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired::class,
68+
],
69+
],
3670
```
3771

38-
You can listen to the following events on account and password expiry:
72+
#### Handling Events
73+
74+
The package automatically registers these events and listeners. You can modify or extend the behaviour by updating the configuration file.
75+
76+
For example, when a user's account or password expires:
77+
78+
- The **`ExpiredAccount`** or **`ExpiredPassword`** event is triggered.
79+
- The **`LogoutOnExpired`** listener handles these events by logging the user out.
80+
81+
#### Customising Listeners
82+
83+
To add custom listeners for these events, update the configuration file (`config/laravel-expiry.php`):
3984

4085
```php
41-
use CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount;
42-
use CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword;
86+
'events' => [
87+
\CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount::class => [
88+
\App\Listeners\YourCustomListener::class,
89+
],
90+
\CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword::class => [
91+
\App\Listeners\YourCustomListener::class,
92+
],
93+
],
4394
```
4495

45-
## Test
96+
With this setup, the package makes it easy to integrate custom logic for handling expiry events.
97+
98+
---
99+
100+
## Testing
46101

47-
Run the following command:
102+
To run the test suite, use the following command:
48103

49104
```bash
50-
vendor/bin/phpunit --testdox --verbose
105+
vendor/bin/pest --testdox
51106
```
52107

108+
The package is fully tested with PestPHP to ensure reliability.
109+
110+
---
111+
53112
## Contributing
54113

55-
Thank you for considering contributing to the `cleaniquecoders/laravel-expiry`!
114+
Thank you for considering contributing to `cleaniquecoders/laravel-expiry`. Contributions are welcome and appreciated!
56115

57-
### Bug Reports
116+
### Reporting Bugs
58117

59-
To encourage active collaboration, it is strongly encourages pull requests, not just bug reports. "Bug reports" may also be sent in the form of a pull request containing a failing test.
118+
If you find a bug, you can either:
60119

61-
However, if you file a bug report, your issue should contain a title and a clear description of the issue. You should also include as much relevant information as possible and a code sample that demonstrates the issue. The goal of a bug report is to make it easy for yourself - and others - to replicate the bug and develop a fix.
120+
- Submit a pull request with a failing test case.
121+
- Create an issue describing the problem clearly with steps to reproduce it.
62122

63-
Remember, bug reports are created in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the bug report will automatically see any activity or that others will jump to fix it. Creating a bug report serves to help yourself and others start on the path of fixing the problem.
123+
### Coding Style
64124

65-
## Coding Style
125+
The package follows **PSR-2** coding standards and **PSR-4** autoloading.
66126

67-
`cleaniquecoders/laravel-expiry` follows the PSR-2 coding standard and the PSR-4 autoloading standard.
127+
---
68128

69129
## License
70130

71-
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
131+
This package is open-source software licensed under the [MIT license](http://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)