Laravel Import Grouper
A powerful VS Code extension that automatically groups and organizes Laravel/PHP import statements for cleaner, more maintainable code.
✨ Features
- 🔄 Auto-grouping: Automatically groups imports from the same namespace
- 💾 Auto-save integration: Groups imports when you save PHP files (configurable)
- 👁️ Preview mode: See changes before applying them
- 📊 Status bar indicator: Shows when imports can be grouped
- 🎨 Smart sorting: Prioritizes Laravel/Illuminate imports
- 🏷️ Alias support: Handles
as
aliases correctly
- ⚙️ Highly configurable: Customize behavior via settings
🚀 Quick Start
- Install the extension
- Open any PHP file with imports
- Use
Ctrl+Shift+I
(or Cmd+Shift+I
on Mac) to group imports
- Or let it automatically group on save!
📝 Examples
Before:
use App\Models\User;
use App\Models\Post;
use App\Models\Comment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
After:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\{Auth, DB};
use App\Models\{Comment, Post, User};
With Aliases:
// Before
use App\Models\User as UserModel;
use App\Models\Post as PostModel;
// After
use App\Models\{Post as PostModel, User as UserModel};
⌨️ Commands & Shortcuts
Command |
Shortcut |
Description |
Group Laravel Imports |
Ctrl+Shift+I |
Groups imports in current file |
Preview Import Grouping |
Ctrl+Shift+Alt+I |
Preview changes before applying |
Note: Use Cmd
instead of Ctrl
on Mac
⚙️ Configuration
Access settings via File > Preferences > Settings
and search for "Laravel Import Grouper":
laravelImportGrouper.autoGroupOnSave
- Type:
boolean
- Default:
true
- Description: Automatically group imports when saving PHP files
laravelImportGrouper.minClassesForGrouping
- Type:
number
- Default:
2
- Description: Minimum classes needed from same namespace to create grouped import
laravelImportGrouper.sortOrder
- Type:
array
- Default:
["Illuminate", "Laravel", "App"]
- Description: Priority order for namespace sorting
laravelImportGrouper.enableStatusBar
- Type:
boolean
- Default:
true
- Description: Show status bar indicator when imports can be grouped
laravelImportGrouper.showPreview
- Type:
boolean
- Default:
true
- Description: Show preview before applying changes
💡 Smart Features
Namespace Priority Sorting
The extension intelligently sorts imports based on your configuration:
- Illuminate/Laravel imports first
- App namespace imports
- Vendor packages
- Alphabetical within each group
Alias Preservation
Correctly handles and preserves import aliases:
use App\Services\{PaymentService as Payment, UserService as Users};
Safely handles imports with inline comments:
use App\Models\User; // Main user model
Status Bar Integration
Shows a helpful indicator in the status bar when imports can be grouped:
📦 5 imports can be grouped
🎯 Use Cases
Perfect for:
- Laravel projects with many model/service imports
- Clean code enthusiasts
- Team standardization of import organization
- Large codebases with many dependencies
- PSR compliance and best practices
🔧 Troubleshooting
Extension not working?
- Make sure you're in a PHP file (
.php
extension)
- Check that imports follow standard PHP
use
syntax
- Verify VS Code language mode is set to PHP
Auto-save too aggressive?
Turn off auto-grouping:
{
"laravelImportGrouper.autoGroupOnSave": false
}
Want different sorting?
Customize the sort order:
{
"laravelImportGrouper.sortOrder": ["Illuminate", "Symfony", "App", "Custom"]
}
🤝 Contributing
Found a bug or have a feature request?
- Check existing issues first
- Create detailed bug reports with code examples
- Feature requests welcome!
📄 License
MIT License - feel free to use in your projects!
🔗 Links
Happy coding! 🚀
Made with ❤️ for the Laravel community