Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Diff Laravel Package

sebastian/diff

Standalone PHP diff component extracted from PHPUnit. Generate unified or strict unified diffs between strings, output only changed lines, or plug in custom output builders. Also parse unified diffs into an object graph for further processing.

View on GitHub
Deep Wiki
Context7

Diff implementation

Frequently asked questions about Diff
How do I install sebastian/diff in a Laravel project?
Use Composer with `composer require sebastian/diff` for production or `composer require --dev sebastian/diff` if only needed for testing. The package has no Laravel-specific dependencies and integrates seamlessly with PHPUnit/Pest.
Can I use sebastian/diff to generate diffs for Laravel test assertions?
Yes. Extend Pest or PHPUnit with a custom assertion using `Differ` and `UnifiedDiffOutputBuilder`. Example: `Pest::extend('diff', fn($expected, $actual) => (new Differ(new UnifiedDiffOutputBuilder))->diff($expected, $actual));` for human-readable failures.
Does sebastian/diff support Laravel’s PHP 8.4+ requirements?
Yes, sebastian/diff supports PHP 8.0+. If your Laravel app uses PHP 8.3, check the changelog for updates or consider alternatives like `symfony/diff` for broader compatibility.
How do I parse Git diffs in Laravel using sebastian/diff?
Use the `Parser` class to convert unified diff strings (e.g., from `Git::getDiff()`) into structured objects. This is useful for changelog generators or automated code review tools in Laravel applications.
What output formats does sebastian/diff support for Laravel debugging?
It provides three built-in formats: `UnifiedDiffOutputBuilder` (PHPUnit-style), `StrictUnifiedDiffOutputBuilder` (Git-compatible), and `DiffOnlyOutputBuilder` (minimal changes). For custom formats (e.g., HTML for Nova), implement `DiffOutputBuilderInterface`.
Is sebastian/diff suitable for diffing large files in Laravel logs or migrations?
While optimized, large diffs (e.g., multi-MB logs) may impact memory. Test performance with your largest expected payload. For production, consider streaming or chunking diff operations in Laravel queues.
How can I integrate sebastian/diff with Laravel Telescope for debugging?
Wrap `Differ` in a service provider to configure default output (e.g., `UnifiedDiffOutputBuilder`). Use Telescope’s `log` method to display diffs in the UI, replacing generic error messages with actionable patch-style output.
Are there alternatives to sebastian/diff for Laravel array/object diffs?
For non-textual data (e.g., arrays), use `spatie/array-diff`. sebastian/diff focuses on string diffs, making it ideal for text-based comparisons like config files, logs, or Git diffs in Laravel.
Can I extend sebastian/diff to create custom diff formats for Laravel APIs?
Yes. Implement `DiffOutputBuilderInterface` to generate formats like JSON or HTML. Example: Create a `JsonDiffOutputBuilder` for API responses or a `HtmlDiffOutputBuilder` for Nova tooltips.
How does sebastian/diff handle thread safety in Laravel’s concurrent environments?
The package is stateless and thread-safe by design. For heavy diff operations in Laravel queues (e.g., batch processing), benchmark performance to avoid memory spikes, but no locks or shared state are required.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai