|
22 | 22 | - [Views](#visit-monitoring-views) |
23 | 23 | - [Ajax Requests](#ajax-requests) |
24 | 24 | - [Visit Monitoring Guest Mode](#visit-monitoring-guest-mode) |
| 25 | + - [Visit Monitoring Custom Conditions](#visit-monitoring-custom-conditions) |
25 | 26 | - [Action Monitoring](#action-monitoring) |
26 | 27 | - [Views](#action-monitoring-views) |
27 | 28 | - [Reverse Proxy Config](#action-monitoring-reverse-proxy-config) |
28 | 29 | - [Action Monitoring Guest Mode](#action-monitoring-guest-mode) |
| 30 | + - [Action Monitoring Custom Conditions](#action-monitoring-custom-conditions) |
29 | 31 | - [Authentication Monitoring](#authentication-monitoring) |
30 | 32 | - [Views](#authentication-monitoring-views) |
31 | 33 | - [How to use in big projects](#how-to-use-in-big-projects) |
@@ -366,6 +368,34 @@ When set to `false`, only authenticated user visits will be recorded. |
366 | 368 | ], |
367 | 369 | ``` |
368 | 370 |
|
| 371 | +<a name="visit-monitoring-custom-conditions"></a> |
| 372 | +### Visit Monitoring Custom Conditions |
| 373 | + |
| 374 | +The `Laravel User Monitoring` package allows you to define custom conditions for visit monitoring. |
| 375 | +Conditions give you full control over when a visit should be logged. |
| 376 | + |
| 377 | +#### 🔧 How It Works |
| 378 | + |
| 379 | +- Conditions are checked before a visit is stored. |
| 380 | +- If any condition returns false, the visit will be skipped. |
| 381 | +- You can define conditions as closures or as class-based rules. |
| 382 | + |
| 383 | +```php |
| 384 | +'visit_monitoring' => [ |
| 385 | + 'conditions' => [ |
| 386 | + // Class-based condition (must implement MonitoringCondition interface) |
| 387 | + \App\Monitoring\YourCustomCondition::class, |
| 388 | + |
| 389 | + // Closure-based condition (receives the Request and authenticated User) |
| 390 | + function (Illuminate\Http\Request $request) { |
| 391 | + $user = $request->user(); |
| 392 | + |
| 393 | + return $user && $user->isAdmin(); |
| 394 | + }, |
| 395 | + ], |
| 396 | +], |
| 397 | +``` |
| 398 | + |
369 | 399 | <a name="action-monitoring"></a> |
370 | 400 | ## Action Monitoring |
371 | 401 |
|
@@ -457,6 +487,34 @@ When set to `false`, only authenticated user visits will be recorded. |
457 | 487 | ], |
458 | 488 | ``` |
459 | 489 |
|
| 490 | +<a name="action-monitoring-custom-conditions"></a> |
| 491 | +### Action Monitoring Custom Conditions |
| 492 | + |
| 493 | +The `Laravel User Monitoring` package lets you define custom conditions for action monitoring (create, update, delete events on models). |
| 494 | +Conditions give you control over when model actions should be logged. |
| 495 | + |
| 496 | +#### 🔧 How It Works |
| 497 | + |
| 498 | +- Conditions are checked before an action is stored. |
| 499 | +- If any condition returns false, the action will be skipped. |
| 500 | +- You can define conditions as closures or class-based rules. |
| 501 | + |
| 502 | +```php |
| 503 | +'action_monitoring' => [ |
| 504 | + 'conditions' => [ |
| 505 | + // Class-based condition (must implement MonitoringCondition interface) |
| 506 | + \App\Monitoring\YourCustomCondition::class, |
| 507 | + |
| 508 | + // Closure-based condition (receives the Request and authenticated User) |
| 509 | + function (Illuminate\Http\Request $request) { |
| 510 | + $user = $request->user(); |
| 511 | + |
| 512 | + return $user && $user->isAdmin(); |
| 513 | + }, |
| 514 | + ], |
| 515 | +], |
| 516 | +``` |
| 517 | + |
460 | 518 | <a name="authentication-monitoring"></a> |
461 | 519 | ## Authentication Monitoring |
462 | 520 |
|
|
0 commit comments