Skip to content

Commit a7f4466

Browse files
authored
Merge pull request #22 from binafy/publish-routes
[1.x] Add publish routes
2 parents 3208642 + 0a1a639 commit a7f4466

File tree

4 files changed

+88
-8
lines changed

4 files changed

+88
-8
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- [Introduction](#introduction)
1212
- [Installation](#installation)
1313
- [Usage](#usage)
14+
- [Configuration](#configuration)
15+
- [Routes Configuration](#routes-configuration)
1416
- [User Configuration](#user-configuration)
1517
- [Foreign Key Type (UUID, ULID, ID)](#foreign-key-type-uuid-ulid-id)
1618
- [Visit Monitoring](#visit-monitoring)
@@ -68,13 +70,19 @@ If you want to publish the views you can use this command:
6870
php artisan vendor:publish --tag="laravel-user-monitoring-views"
6971
```
7072

71-
If you want to publish the middlewares you can use this command:
73+
If you want to publish the middleware you can use this command:
7274

7375
```shell
7476
php artisan vendor:publish --tag="laravel-user-monitoring-middlewares"
7577
```
7678

77-
For convenience, you can use this command to publish config and migration files:
79+
If you want to publish the routes you can use this command:
80+
81+
```shell
82+
php artisan vendor:publish --tag="laravel-user-monitoring-routes"
83+
```
84+
85+
For convenience, you can use this command to publish config, migration, and ... files:
7886

7987
```shell
8088
php artisan vendor:publish --provider="Binafy\LaravelUserMonitoring\Providers\LaravelUserMonitoringServiceProvider"
@@ -85,8 +93,31 @@ After publishing, run the `php artisan migrate` command.
8593
<a name="usage"></a>
8694
## Usage
8795

88-
The `Laravel-User-Monitoring`, just need to use middleware, traits, etc ... and it's not hard, enjoy :)
96+
The `Laravel-User-Monitoring`, just need to use middleware, traits, etc ... and it's not hard, enjoys :)
8997

98+
<a name="routes-configuration"></a>
99+
## Routes Configuration
100+
101+
If you want to customize the routes, you can publish the route file with this command:
102+
103+
```shell
104+
php artisan vendor:publish --tag="laravel-user-monitoring-routes"
105+
```
106+
107+
After, you can go to the `routes/user-monitoring.php` file and customize the routes.
108+
109+
Also, if you want to change the route file name, you can go to the config file and change the `file_path`:
110+
111+
```php
112+
/*
113+
* Configurations.
114+
*/
115+
'config' => [
116+
'routes' => [
117+
'file_path' => 'routes/user-monitoring.php',
118+
],
119+
],
120+
```
90121

91122
<a name="user-configuration"></a>
92123
## User Configuration

config/user-monitoring.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?php
22

33
return [
4+
/*
5+
* Configurations.
6+
*/
7+
'config' => [
8+
'routes' => [
9+
'file_path' => 'routes/user-monitoring.php',
10+
],
11+
],
12+
413
/*
514
* User properties.
615
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Binafy\LaravelUserMonitoring\Providers;
4+
5+
use Binafy\LaravelUserMonitoring\Middlewares\VisitMonitoringMiddleware;
6+
use Illuminate\Foundation\Support\Providers\RouteServiceProvider;
7+
use Illuminate\Support\Facades\Route;
8+
9+
class LaravelUserMonitoringRouteServiceProvider extends RouteServiceProvider
10+
{
11+
/**
12+
* Register files.
13+
*
14+
* @return void
15+
*/
16+
public function register()
17+
{
18+
$path = base_path(
19+
config('user-monitoring.config.routes.file_path', 'routes/user-monitoring.php')
20+
);
21+
22+
if (! file_exists($path)) {
23+
$path = __DIR__ . '/../../routes/web.php';
24+
}
25+
26+
Route::middleware('web')
27+
->middleware(VisitMonitoringMiddleware::class)
28+
->group($path);
29+
}
30+
}

src/Providers/LaravelUserMonitoringServiceProvider.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Binafy\LaravelUserMonitoring\Commands\RemoveVisitMonitoringRecordsCommand;
66
use Binafy\LaravelUserMonitoring\Middlewares\VisitMonitoringMiddleware;
7-
use Illuminate\Support\Facades\Route;
87
use Illuminate\Support\ServiceProvider;
98
use Illuminate\View\View;
109

@@ -23,11 +22,9 @@ public function register()
2322
$this->commands(RemoveVisitMonitoringRecordsCommand::class);
2423

2524
$this->app['router']->aliasMiddleware('monitor-visit-middleware', VisitMonitoringMiddleware::class);
26-
$this->app->register(LaravelUserMonitoringEventServiceProvider::class);
2725

28-
Route::middleware('web')
29-
->middleware(VisitMonitoringMiddleware::class)
30-
->group(__DIR__ . '/../../routes/web.php');
26+
$this->app->register(LaravelUserMonitoringEventServiceProvider::class);
27+
$this->app->register(LaravelUserMonitoringRouteServiceProvider::class);
3128
}
3229

3330
/**
@@ -41,6 +38,7 @@ public function boot()
4138
$this->publishMigrations();
4239
$this->publishViews();
4340
$this->publishMiddleware();
41+
$this->publishRoute();
4442

4543
$this->viewComposer();
4644
}
@@ -93,6 +91,18 @@ private function publishMiddleware()
9391
], 'laravel-user-monitoring-middlewares');
9492
}
9593

94+
/**
95+
* Publish route files.
96+
*
97+
* @return void
98+
*/
99+
private function publishRoute()
100+
{
101+
$this->publishes([
102+
__DIR__ . '/../../routes/web.php' => base_path('routes/user-monitoring.php'),
103+
], 'laravel-user-monitoring-routes');
104+
}
105+
96106
/**
97107
* View Composer.
98108
*

0 commit comments

Comments
 (0)