Skip to content

Commit 3f65374

Browse files
committed
refactor: Enhance package configuration with interactive setup command 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.
1 parent fae8e3f commit 3f65374

1 file changed

Lines changed: 30 additions & 21 deletions

File tree

src/RequestAnalyticsServiceProvider.php

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,59 @@
22

33
namespace MeShaon\RequestAnalytics;
44

5-
use MeShaon\RequestAnalytics\Commands\SetupCommand;
65
use Illuminate\Contracts\Http\Kernel;
76
use MeShaon\RequestAnalytics\Commands\RequestAnalyticsCommand;
7+
use MeShaon\RequestAnalytics\Commands\SetupCommand;
88
use MeShaon\RequestAnalytics\Http\Middleware\AnalyticsDashboardMiddleware;
99
use MeShaon\RequestAnalytics\Http\Middleware\APIRequestCapture;
1010
use MeShaon\RequestAnalytics\Http\Middleware\WebRequestCapture;
1111
use Spatie\LaravelPackageTools\Package;
1212
use Spatie\LaravelPackageTools\PackageServiceProvider;
13+
use Spatie\LaravelPackageTools\Commands\InstallCommand;
1314

1415
class RequestAnalyticsServiceProvider extends PackageServiceProvider
1516
{
1617
public function configurePackage(Package $package): void
1718
{
18-
$this->publishes([
19-
__DIR__.'/../resources/assets' => public_path('/'),
20-
], 'assets');
21-
22-
$this->publishes([
23-
__DIR__.'/../config/request-analytics.php' => config_path('request-analytics.php'),
24-
], 'config');
25-
2619
$package
2720
->name('laravel-request-analytics')
2821
->hasConfigFile()
2922
->hasViews()
30-
->hasRoute('web')
31-
->hasRoute('api')
23+
->hasRoutes(['web', 'api'])
3224
->hasAssets()
33-
->hasMigration('create_request_analytics_table')
34-
->hasCommand(RequestAnalyticsCommand::class);
25+
->hasMigrations(['create_request_analytics_table', 'add_indexes_to_request_analytics_table'])
26+
->hasCommands([
27+
RequestAnalyticsCommand::class,
28+
SetupCommand::class,
29+
])
30+
->hasInstallCommand(function (InstallCommand $command) {
31+
$command
32+
->startWith(function (InstallCommand $command) {
33+
$command->info('Installing Laravel Request Analytics...');
34+
$command->info('This package will help you track and analyze your application requests.');
35+
})
36+
->publishConfigFile()
37+
->publishAssets()
38+
->publish('views')
39+
->askToRunMigrations()
40+
->endWith(function (InstallCommand $command) {
41+
$command->info('Laravel Request Analytics has been installed successfully!');
42+
$command->info('You can now visit /analytics to view your dashboard.');
43+
$command->info('Check the documentation for configuration options.');
44+
})
45+
->askToStarRepoOnGitHub('me-shaon/laravel-request-analytics');
46+
});
47+
}
3548

49+
50+
public function packageRegistered(): void
51+
{
3652
$this->registerMiddlewareAsAliases();
3753
}
3854

39-
public function boot(): void
55+
public function packageBooted(): void
4056
{
41-
parent::boot();
4257
$this->pushMiddlewareToPipeline();
43-
44-
if ($this->app->runningInConsole()) {
45-
$this->commands([
46-
SetupCommand::class,
47-
]);
48-
}
4958
}
5059

5160
private function registerMiddlewareAsAliases(): void

0 commit comments

Comments
 (0)