Skip to content

refactor: Modernize service provider using Laravel Package Tools features#52

Merged
me-shaon merged 19 commits intomainfrom
refactor-service-provider
Sep 21, 2025
Merged

refactor: Modernize service provider using Laravel Package Tools features#52
me-shaon merged 19 commits intomainfrom
refactor-service-provider

Conversation

@theihasan
Copy link
Copy Markdown
Collaborator

Refactors the RequestAnalyticsServiceProvider to fully leverage Laravel Package Tools capabilities, providing a cleaner and more maintainable package structure.

Changes Made

Service Provider Refactoring

  • Removed manual publishes() calls - Now handled automatically by Laravel Package Tools
  • Consolidated route registration - Using hasRoutes(['web', 'api']) instead of multiple hasRoute() calls
  • Enhanced migration handling - Added support for both existing migration files
  • Streamlined command registration - Using hasCommands() array instead of manual registration

Install Command Enhancement

  • Added interactive install command - Users can now run php artisan request-analytics:install
  • Includes user-friendly messaging - Welcome and success messages with emojis
  • GitHub star integration - Prompts users to star the repository
  • Automatic publishing - Handles config, assets, views, and migrations

Architecture Improvements

  • Used lifecycle hooks - packageRegistered() and packageBooted() for proper timing
  • Cleaner separation of concerns - Middleware registration moved to appropriate lifecycle methods
  • Removed boot() override - No longer needed with proper lifecycle hook usage

Benefits

Better Developer Experience - One-command installation
Cleaner Codebase - Reduced manual publishing configuration
Standardized Approach - Follows Laravel Package Tools conventions
Enhanced Maintainability - Less boilerplate code
Improved User Onboarding - Interactive installation process

Testing

The refactored service provider maintains full backward compatibility while providing these enhancements:

  • All existing publish tags still work (request-analytics-config, request-analytics-assets, etc.)
  • Middleware registration continues to function identically
  • All commands remain available
  • Package functionality unchanged

Installation Experience

Users now get this improved installation flow:

$ php artisan request-analytics:install

Installing Laravel Request Analytics...
This package will help you track and analyze your application requests.
Publishing config...
Publishing assets...
Publishing views...
Would you like to run the migrations now? (yes/no) [no]:
Would you like to star our repo on GitHub? (yes/no) [no]:
Laravel Request Analytics has been installed successfully!
You can now visit /analytics to view your dashboard.
Check the documentation for configuration options.

theihasan and others added 3 commits September 17, 2025 18:12
…d and improved route handling

- Added interactive setup command for easier installation and configuration.
- Updated route handling to support both web and API routes.
- Consolidated asset and migration publishing into the setup process.
…ublishing options

- Revamped installation section with a quick installation command and interactive installer details.
- Added comprehensive setup command for file publishing and migrations.
- Introduced granular publishing options for individual components.
- Included a new "Getting Started" section to guide users post-installation.
theihasan and others added 16 commits September 17, 2025 18:53
- Deleted the RequestAnalyticsCommand and SetupCommand classes as they are no longer needed.
- Updated the RequestAnalyticsServiceProvider to remove references to the deleted commands.
…licity

- Updated installation section to emphasize a two-command setup process.
- Removed the alternative setup command to streamline user experience.
- Clarified post-installation steps for accessing the analytics dashboard.
- Deleted the SetupCommandTest file, which is no longer needed following the removal of the SetupCommand class.
- This change streamlines the test suite by eliminating tests for commands that have been deprecated.
- Enhanced the RequestAnalyticsServiceProvider to include migration publishing as part of the setup process.
- This addition allows users to easily manage database migrations alongside other configuration tasks.
@me-shaon me-shaon merged commit 91976f9 into main Sep 21, 2025
18 checks passed
@me-shaon me-shaon deleted the refactor-service-provider branch September 21, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants