Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Laravel Import GrouperNew to Visual Studio Code? Get it now.
Laravel Import Grouper

Laravel Import Grouper

Maulana Ibrahim

|
3 installs
| (1) | Free
Automatically group Laravel imports with same namespace
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

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

  1. Install the extension
  2. Open any PHP file with imports
  3. Use Ctrl+Shift+I (or Cmd+Shift+I on Mac) to group imports
  4. 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:

  1. Illuminate/Laravel imports first
  2. App namespace imports
  3. Vendor packages
  4. Alphabetical within each group

Alias Preservation

Correctly handles and preserves import aliases:

use App\Services\{PaymentService as Payment, UserService as Users};

Comment Preservation

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?

  1. Make sure you're in a PHP file (.php extension)
  2. Check that imports follow standard PHP use syntax
  3. 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?

  1. Check existing issues first
  2. Create detailed bug reports with code examples
  3. Feature requests welcome!

📄 License

MIT License - feel free to use in your projects!

🔗 Links

  • VS Code Marketplace
  • GitHub Repository
  • Report Issues

Happy coding! 🚀

Made with ❤️ for the Laravel community

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft