Overview
The DiffViewsCommand is an Artisan command that compares published form views in your application with the original package views. It identifies redundant views (identical to package) and modified views (customized), with optional cleanup functionality.
Namespace: Javaabu\Forms\Commands
Extends: Illuminate\Console\Command
Class Definition
class DiffViewsCommand extends Command
Properties
forms:diff-views
{--only-redundant : Show only published views that are identical to the package views}
{--delete-redundant : Delete redundant published views after listing them}
Find redundant or modified published form views in your application.
Command Signature
php artisan forms:diff-views [options]
Options
Show only redundant views (identical to package). Hides modified views from output.
Delete redundant published views after listing them. Prompts for confirmation before deletion.
Methods
handle
public function handle(): int
Main command execution method. Performs the following:
- Locates package and published view directories
- Scans for published view files
- Compares each published file with package version
- Displays results in a table
- Shows summary statistics
- Optionally deletes redundant files
Returns: int - Exit code (0 for success, 1 for error)
getViewFiles
protected function getViewFiles(string $basePath, Filesystem $filesystem): array
The base directory to scan.
filesystem
Illuminate\Filesystem\Filesystem
required
The filesystem instance.
Scans a directory for all .blade.php files recursively.
Returns: array - Associative array where keys are relative paths and values are absolute paths:
[
'bootstrap5/input.blade.php' => '/full/path/to/bootstrap5/input.blade.php',
'bootstrap5/select.blade.php' => '/full/path/to/bootstrap5/select.blade.php',
// ...
]
printSummary
protected function printSummary(array $counts): void
Array with ‘redundant’ and ‘modified’ counts.
Prints a summary of the scan results.
Returns: void
Output Format:
Summary:
Redundant (can be deleted): 3
Modified (customized override): 5
deleteRedundantViews
protected function deleteRedundantViews(
array $redundantFiles,
Filesystem $filesystem
): void
Array of redundant files to delete (relative path => absolute path).
filesystem
Illuminate\Filesystem\Filesystem
required
The filesystem instance.
Prompts for confirmation and deletes redundant view files.
Returns: void
Behavior:
- Shows confirmation prompt before deleting
- Deletes files one by one
- Displays status for each deletion
- Shows error messages if deletion fails
Usage Examples
View All Published Views
php artisan forms:diff-views
Output:
┌───────────┬──────────────────────────────────┐
│ Status │ View │
├───────────┼──────────────────────────────────┤
│ REDUNDANT │ bootstrap5/alert.blade.php │
│ MODIFIED │ bootstrap5/input.blade.php │
│ REDUNDANT │ bootstrap5/button.blade.php │
│ MODIFIED │ bootstrap5/select.blade.php │
└───────────┴──────────────────────────────────┘
Summary:
Redundant (can be deleted): 2
Modified (customized override): 2
View Only Redundant Files
php artisan forms:diff-views --only-redundant
Output:
┌───────────┬──────────────────────────────────┐
│ Status │ View │
├───────────┼──────────────────────────────────┤
│ REDUNDANT │ bootstrap5/alert.blade.php │
│ REDUNDANT │ bootstrap5/button.blade.php │
│ REDUNDANT │ tailwind/input.blade.php │
└───────────┴──────────────────────────────────┘
Summary:
Redundant (can be deleted): 3
Modified (customized override): 0
Delete Redundant Files
php artisan forms:diff-views --delete-redundant
Output:
┌───────────┬──────────────────────────────────┐
│ Status │ View │
├───────────┼──────────────────────────────────┤
│ REDUNDANT │ bootstrap5/alert.blade.php │
│ REDUNDANT │ bootstrap5/button.blade.php │
└───────────┴──────────────────────────────────┘
Summary:
Redundant (can be deleted): 2
Modified (customized override): 0
Delete 2 redundant view file(s) from your application?
yes
› no
DELETED bootstrap5/alert.blade.php
DELETED bootstrap5/button.blade.php
Delete Only Redundant Files (Combined)
php artisan forms:diff-views --only-redundant --delete-redundant
Output:
┌───────────┬──────────────────────────────────┐
│ Status │ View │
├───────────┼──────────────────────────────────┤
│ REDUNDANT │ bootstrap5/alert.blade.php │
└───────────┴──────────────────────────────────┘
Summary:
Redundant (can be deleted): 1
Modified (customized override): 0
Delete 1 redundant view file(s) from your application?
yes
› no
DELETED bootstrap5/alert.blade.php
View Status Types
REDUNDANT (Gray)
A published view that is identical to the package view.
Meaning:
- File content matches package exactly
- No customizations have been made
- Can be safely deleted
- Will fall back to package view if deleted
Example:
REDUNDANT bootstrap5/alert.blade.php
MODIFIED (Yellow)
A published view that is different from the package view.
Meaning:
- File has been customized
- Contains user modifications
- Should NOT be deleted
- Represents intentional override
Example:
MODIFIED bootstrap5/input.blade.php
Use Cases
1. Clean Up After Package Update
After updating the package, some of your published views might now match the new package versions:
# Check for redundant files
php artisan forms:diff-views --only-redundant
# Delete them if found
php artisan forms:diff-views --only-redundant --delete-redundant
2. Audit Published Views
Review which views you’ve customized:
# See all published views and their status
php artisan forms:diff-views
# Only customized views
php artisan forms:diff-views --only-redundant
# (Everything NOT shown is customized)
3. Before Major Package Update
Before a major package update, identify your customizations:
php artisan forms:diff-views
# Take note of MODIFIED views
# These might need manual updates after package upgrade
4. Reduce Maintenance Burden
Remove unnecessary published files:
# Find and delete redundant views
php artisan forms:diff-views --delete-redundant
# This reduces the number of files you need to maintain
Comparison Logic
The command compares files using byte-by-byte comparison:
$packageContent = file_get_contents('/path/to/package/view.blade.php');
$publishedContent = file_get_contents('/path/to/published/view.blade.php');
if ($packageContent === $publishedContent) {
// REDUNDANT
} else {
// MODIFIED
}
Important Notes:
- Even whitespace differences count as modified
- Comments are not ignored
- Comparison is exact binary match
File Locations
Package Views: vendor/javaabu/forms/resources/views/
Published Views: resources/views/vendor/forms/
Comparison:
vendor/javaabu/forms/resources/views/bootstrap5/input.blade.php
vs
resources/views/vendor/forms/bootstrap5/input.blade.php
Deletion Safety
The command only deletes redundant files:
✅ Safe to Delete:
- REDUNDANT views (identical to package)
- Deleting falls back to package version
- No functionality is lost
❌ Never Deleted:
- MODIFIED views (customized)
- Protected automatically
- User modifications are preserved
Error Handling
Package directory not found:
Package view directory not found.
No published views:
No published views found in your application.
No redundant views:
No redundant published views found.
Deletion failed:
FAILED bootstrap5/input.blade.php: Permission denied
Workflow Example
Complete workflow for managing published views:
# 1. Publish views for customization
php artisan forms:publish-view --all
# 2. Customize some views
# Edit: resources/views/vendor/forms/bootstrap5/input.blade.php
# 3. Later, check status
php artisan forms:diff-views
# Output shows:
# REDUNDANT: alert.blade.php (didn't customize)
# MODIFIED: input.blade.php (customized)
# 4. Clean up redundant files
php artisan forms:diff-views --only-redundant --delete-redundant
# 5. After package update, check again
composer update javaabu/forms
php artisan forms:diff-views
# 6. Republish if needed
php artisan forms:publish-view