|
2 | 2 |
|
3 | 3 | namespace MeShaon\RequestAnalytics; |
4 | 4 |
|
5 | | -use MeShaon\RequestAnalytics\Commands\SetupCommand; |
6 | 5 | use Illuminate\Contracts\Http\Kernel; |
7 | 6 | use MeShaon\RequestAnalytics\Commands\RequestAnalyticsCommand; |
| 7 | +use MeShaon\RequestAnalytics\Commands\SetupCommand; |
8 | 8 | use MeShaon\RequestAnalytics\Http\Middleware\AnalyticsDashboardMiddleware; |
9 | 9 | use MeShaon\RequestAnalytics\Http\Middleware\APIRequestCapture; |
10 | 10 | use MeShaon\RequestAnalytics\Http\Middleware\WebRequestCapture; |
11 | 11 | use Spatie\LaravelPackageTools\Package; |
12 | 12 | use Spatie\LaravelPackageTools\PackageServiceProvider; |
| 13 | +use Spatie\LaravelPackageTools\Commands\InstallCommand; |
13 | 14 |
|
14 | 15 | class RequestAnalyticsServiceProvider extends PackageServiceProvider |
15 | 16 | { |
16 | 17 | public function configurePackage(Package $package): void |
17 | 18 | { |
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 | | - |
26 | 19 | $package |
27 | 20 | ->name('laravel-request-analytics') |
28 | 21 | ->hasConfigFile() |
29 | 22 | ->hasViews() |
30 | | - ->hasRoute('web') |
31 | | - ->hasRoute('api') |
| 23 | + ->hasRoutes(['web', 'api']) |
32 | 24 | ->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 | + } |
35 | 48 |
|
| 49 | + |
| 50 | + public function packageRegistered(): void |
| 51 | + { |
36 | 52 | $this->registerMiddlewareAsAliases(); |
37 | 53 | } |
38 | 54 |
|
39 | | - public function boot(): void |
| 55 | + public function packageBooted(): void |
40 | 56 | { |
41 | | - parent::boot(); |
42 | 57 | $this->pushMiddlewareToPipeline(); |
43 | | - |
44 | | - if ($this->app->runningInConsole()) { |
45 | | - $this->commands([ |
46 | | - SetupCommand::class, |
47 | | - ]); |
48 | | - } |
49 | 58 | } |
50 | 59 |
|
51 | 60 | private function registerMiddlewareAsAliases(): void |
|
0 commit comments