- How do I install and set up PrivacyFilter in a Laravel 10+ project?
- Run `composer require directorytree/privacy-filter` first, then execute `php artisan privacy-filter:install` to download the binary and GGUF model. The package auto-detects your OS and installs the correct files in `storage/app/privacy-filter/` by default. Use `--force` to overwrite existing files if needed.
- Which Laravel versions and PHP versions does this package support?
- PrivacyFilter is optimized for Laravel 10+ and requires PHP 8.1+. It leverages PHP’s type safety features and modern Laravel service container patterns. Avoid PHP 7.x due to missing dependencies and binary compatibility issues.
- Can I customize the privacy detection model for domain-specific terms (e.g., internal jargon or HIPAA-specific rules)?
- Yes, the underlying GGUF model supports customization. You can fine-tune the model or replace it entirely by updating the `model_url` in the published config file. The package also allows overriding the model path via `.env` (e.g., `PRIVACY_FILTER_MODEL_PATH`).
- How do I integrate PrivacyFilter into Laravel middleware for real-time request scrubbing?
- Create a middleware class (e.g., `FilterPrivateData`) that uses the `PrivacyFilter::scan()` method to process incoming requests. Inject the facade via Laravel’s container and apply the middleware to routes or globally in `app/Http/Kernel.php`. Example: `PrivacyFilter::scan($request->input('content'))->replace()`.
- What happens if the C++ binary fails to load in production? Does it degrade gracefully?
- The package includes fallback logic. If the binary fails, it throws a `BinaryNotFoundException` by default. Configure graceful degradation by implementing a feature flag in `config/privacy-filter.php` or wrapping calls in a try-catch block. Log skipped operations for observability.
- Is PrivacyFilter suitable for high-traffic APIs where low latency is critical?
- For high-traffic APIs, avoid synchronous filtering in middleware. Instead, use Laravel queues to process large texts asynchronously. Benchmark with payloads >10K characters and cache filtered outputs if idempotency is acceptable. Async processing adds ~50–200ms latency depending on queue backend.
- How do I update the privacy detection model to the latest version?
- Run `php artisan privacy-filter:update` to fetch the latest model from the configured `model_url`. The package checks for updates automatically during installation but doesn’t auto-update in production. For CI/CD, add this to your deployment script or schedule it via Laravel’s task scheduler.
- Are there any licensing costs or restrictions for using the GGUF model or binary?
- The package itself is MIT-licensed, but the GGUF model and binary may have separate licensing terms. Check the [PrivacyFilterBinaries repository](https://github.com/DirectoryTree/PrivacyFilterBinaries) for details. Most models are permissive, but commercial use may require attribution or additional terms.
- How can I log or audit privacy filtering decisions for compliance (e.g., GDPR/HIPAA)?
- Extend the package by overriding the `scan()` method or use Laravel’s logging system to record filtered content, matches, and replacements. Example: `Log::info('PII detected', ['text' => $original, 'filtered' => $filtered])`. For audits, store logs in a dedicated table with timestamps and user context.
- What are the alternatives to PrivacyFilter for PII detection in Laravel?
- Alternatives include PHP libraries like `egulias/email-validator` (for emails only), commercial APIs like AWS Comprehend or Google Cloud Natural Language, or open-source tools like `spatie/laravel-activitylog` (for activity tracking). PrivacyFilter stands out for its offline, high-performance C++ backend and Laravel-native integration.