- How do I install php-htmldiff in a Laravel project?
- Run `composer require caxy/php-htmldiff` to install via Composer. No additional Laravel-specific setup is required for basic usage, though you can register it as a singleton in a service provider for reusable configuration.
- Can I use this package to compare HTML emails or dynamic content in Laravel?
- Yes, php-htmldiff works well for comparing HTML emails or dynamic content. For large diffs (e.g., emails), wrap the diff generation in a Laravel queue job to avoid timeouts and use caching for repeated comparisons.
- Does php-htmldiff support Laravel Blade templates or testing frameworks like Pest?
- It integrates seamlessly with Blade via custom helpers or direct usage in controllers. For Pest, you can create a custom assertion like `assertHtmlDiff()` to compare HTML output with visual diffs in tests.
- What Laravel versions are compatible with this package?
- The package supports PHP 7.3+ and is fully compatible with Laravel 8, 9, and 10. For older Laravel versions (7.x), ensure PHP 7.3+ is used, as the package relies on modern PHP features.
- How do I customize the CSS styling for diff output in Laravel?
- Include the default CSS from the package demo or create your own. Use Laravel’s asset pipeline (e.g., Vite or Mix) to compile a custom CSS file for the diff output, or inline it directly in your Blade templates.
- Is there a way to cache diff results for performance?
- Yes, use Laravel’s cache system or the optional `doctrine/cache` dependency. Configure caching in the `HtmlDiffConfig` object or wrap diff generation in `cache()->remember()` for repeated comparisons.
- Can I store diffs in a database or filesystem for later use?
- Diffs can be stored in a `longtext` database column or saved to the filesystem (e.g., `storage/app/diffs/`). For large diffs, consider compressing them with `gzencode()` before storage.
- What are the alternatives to php-htmldiff for HTML diffing in Laravel?
- Alternatives include `str_diff()` for simple string-based diffs (less accurate for HTML) or DOM-based tools like `DOMDocument` (heavier). php-htmldiff is optimized for visual HTML diffs with minimal overhead.
- How do I handle malformed HTML or edge cases like Unicode text?
- Pre-process input with `htmlspecialchars_decode()` for malformed HTML. The package handles Unicode and RTL text (e.g., Arabic) natively. For self-closing tags like `<img/>`, ensure they’re properly formatted in the input.
- Is there a Symfony bundle available, and can it be used in Laravel?
- Yes, the `caxy/htmldiff-bundle` provides Symfony integration (e.g., Twig extensions). While it’s Symfony-focused, you can adapt its configuration logic for Laravel by manually binding the service in a Laravel service provider.