- How do I install SanityCheck in a Laravel 10 project?
- Run `composer require chameleon-system/sanitycheck` in your project root. The package requires PHP 8.0+ and Laravel 9/10. Check the `Resources/doc/Installation` folder for Laravel-specific setup steps, like binding the service provider in `config/app.php`.
- Can I use this for API request validation instead of Laravel’s built-in Validator?
- Yes, but it’s designed for broader system checks (e.g., config, disk space, external APIs). For API payloads, pair it with Laravel’s `FormRequest` or middleware. Example: `SanityCheck::validate($request->all(), ['rules' => [...]])` in a middleware. Avoid replacing `Validator` for complex business logic.
- Does SanityCheck support custom validation rules for my Laravel models?
- The package allows defining custom checks, but Laravel-specific model validation (e.g., Eloquent rules) isn’t natively supported. Extend the `Check` class or use it alongside Laravel’s `Validator` for model-level checks. Check the `Resources/doc` for rule extension examples.
- Will this work in CI/CD pipelines for pre-deployment checks?
- Absolutely. Run checks via CLI (e.g., `php artisan sanitycheck:run`) in your CI pipeline to validate configs, database connections, or external services before deployment. Use the `--fail-fast` flag to halt builds on critical failures.
- Are there performance concerns for high-traffic Laravel apps?
- SanityCheck is lightweight but avoid CPU-heavy checks (e.g., large dataset scans) in request middleware. Use it for pre-flight checks (e.g., in `bootstrap/app.php`) or async jobs (Laravel Queues) to minimize impact. Benchmark with `php artisan tinker` for critical paths.
- How do I handle false positives in production?
- Tune checks by adjusting thresholds (e.g., disk space warnings) or skipping non-critical checks in production via config. Use the `SanityCheck::setEnvironment()` method to exclude dev-only checks. Log results with `SanityCheck::report()` for debugging.
- Does this replace Laravel Pint, PHPStan, or Psalm for static analysis?
- No. SanityCheck focuses on runtime/system checks (e.g., config, APIs), while tools like PHPStan analyze code structure. Use both: SanityCheck for deployment sanity and PHPStan for static code validation. The package complements, not replaces, these tools.
- Can I integrate this with Laravel’s event system for async checks?
- Yes. Dispatch checks via Laravel Events (e.g., `Event::dispatch(new SystemCheckEvent())`) and listen with `SanityCheck::run()` in an event handler. Example: Trigger checks after `job:failed` events to validate recovery systems.
- What Laravel versions and PHP dependencies does this support?
- The package targets PHP 8.0+ and Laravel 9/10. Verify compatibility by checking the `composer.json` `require` section. If using Laravel 8.x, downgrade PHP or fork the package for legacy support.
- How do I test SanityCheck in a Laravel project?
- Mock checks in PHPUnit using `SanityCheck::shouldFail()` or `shouldPass()` assertions. Test CLI commands with `Artisan::call()` and validate output. For integration tests, simulate failed checks (e.g., fake disk full errors) and assert middleware/route behavior.