Skip to content

Commit 0786734

Browse files
committed
Add support for activity details.
1 parent a9b77c0 commit 0786734

File tree

8 files changed

+41
-11
lines changed

8 files changed

+41
-11
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Laravel logger is an activity event logger for your Laravel or Lumen application
3939
|Routing Events can recording using middleware|
4040
|Records activity timestamps|
4141
|Records activity description|
42+
|Records activity details (optional)|
4243
|Records activity user type with crawler detection.|
4344
|Records activity Method|
4445
|Records activity Route|
@@ -216,20 +217,25 @@ When using the trait you can customize the event description.
216217
To use the trait:
217218
1. Include the call in the head of your class file:
218219

219-
```php
220-
use jeremykenedy\LaravelLogger\App\Http\Traits\ActivityLogger;
221-
```
220+
```php
221+
use jeremykenedy\LaravelLogger\App\Http\Traits\ActivityLogger;
222+
```
222223

223224
2. Include the trait call in the opening of your class:
224225

225-
```php
226-
use ActivityLogger;
227-
```
226+
```php
227+
use ActivityLogger;
228+
```
228229

229230
3. You can record the activity my calling the traits method:
230-
```
231-
ActivityLogger::activity("Logging this activity.");
232-
```
231+
```
232+
ActivityLogger::activity("Logging this activity.");
233+
```
234+
235+
Or as bellow to include extended activity details:
236+
```
237+
ActivityLogger::activity("Logging this activity.", "Additional activity details.");
238+
```
233239

234240
### Routes
235241
##### Laravel Activity Dashbaord Routes

src/App/Http/Traits/ActivityLogger.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ trait ActivityLogger
1414
/**
1515
* Laravel Logger Log Activity.
1616
*
17-
* @param string $description
17+
* @param null $description
18+
* @param null $details
1819
*
1920
* @return void
2021
*/
21-
public static function activity($description = null)
22+
public static function activity($description = null, $details = null)
2223
{
2324
$userType = trans('LaravelLogger::laravel-logger.userTypes.guest');
2425
$userId = null;
@@ -62,6 +63,7 @@ public static function activity($description = null)
6263

6364
$data = [
6465
'description' => $description,
66+
'details' => $details,
6567
'userType' => $userType,
6668
'userId' => $userId,
6769
'route' => Request::fullUrl(),
@@ -95,6 +97,7 @@ private static function storeActivity($data)
9597
{
9698
Activity::create([
9799
'description' => $data['description'],
100+
'details' => $data['details'],
98101
'userType' => $data['userType'],
99102
'userId' => $data['userId'],
100103
'route' => $data['route'],

src/App/Models/Activity.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Activity extends Model
5757
*/
5858
protected $fillable = [
5959
'description',
60+
'details',
6061
'userType',
6162
'userId',
6263
'route',
@@ -69,6 +70,7 @@ class Activity extends Model
6970

7071
protected $casts = [
7172
'description' => 'string',
73+
'details' => 'string',
7274
'user' => 'integer',
7375
'route' => 'string',
7476
'ipAddress' => 'string',
@@ -134,6 +136,7 @@ public static function rules($merge = [])
134136
return array_merge(
135137
[
136138
'description' => 'required|string',
139+
'details' => 'nullable|string',
137140
'userType' => 'required|string',
138141
'userId' => 'nullable|integer',
139142
'route' => 'nullable|'.$route_url_check,

src/database/migrations/2017_11_04_103444_create_laravel_logger_activity_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function up()
2323
Schema::connection($connection)->create($table, function (Blueprint $table) {
2424
$table->increments('id');
2525
$table->longText('description');
26+
$table->longText('details')->nullable();
2627
$table->string('userType');
2728
$table->integer('userId')->nullable();
2829
$table->longText('route')->nullable();

src/resources/lang/de/laravel-logger.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
'id' => 'Aktivitätslog ID:',
8787
'ip' => 'IP Adresse',
8888
'description' => 'Beschreibung',
89+
'details' => 'Einzelheiten',
8990
'userType' => 'Nutzertyp',
9091
'userId' => 'Nutzer ID',
9192
'route' => 'Route',
@@ -107,6 +108,10 @@
107108
'userCreatedAt' => 'Erstellt',
108109
'userUpdatedAt' => 'Bearbeitet',
109110
],
111+
112+
'fields' => [
113+
'none' => 'Keiner',
114+
],
110115
],
111116

112117
],

src/resources/lang/en/laravel-logger.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
'id' => 'Activity Log ID:',
8787
'ip' => 'Ip Address',
8888
'description' => 'Description',
89+
'details' => 'Details',
8990
'userType' => 'User Type',
9091
'userId' => 'User Id',
9192
'route' => 'Route',
@@ -107,6 +108,10 @@
107108
'userCreatedAt' => 'Created',
108109
'userUpdatedAt' => 'Updated',
109110
],
111+
112+
'fields' => [
113+
'none' => 'None',
114+
],
110115
],
111116

112117
],

src/resources/lang/fr/laravel-logger.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
'id' => 'Activité Id :',
8585
'ip' => 'Adresse Ip',
8686
'description' => 'Description',
87+
'details' => 'Détails',
8788
'userType' => 'Type Utilisateur',
8889
'userId' => 'Id Utilisateur',
8990
'route' => 'Route',
@@ -105,6 +106,10 @@
105106
'userCreatedAt' => 'Créé le',
106107
'userUpdatedAt' => 'Actualisé le',
107108
],
109+
110+
'fields' => [
111+
'none' => 'Aucun',
112+
],
108113
],
109114

110115
],

src/resources/views/logger/activity-log-item.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@
191191
<dd>{{$activity->id}}</dd>
192192
<dt>{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.labels.description') !!}</dt>
193193
<dd>{{$activity->description}}</dd>
194+
<dt>{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.labels.details') !!}</dt>
195+
<dd>@if($activity->details){{$activity->details}}@else{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.fields.none') !!}@endif</dd>
194196
<dt>{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.labels.route') !!}</dt>
195197
<dd>
196198
<a href="@if($activity->route != '/')/@endif{{$activity->route}}">

0 commit comments

Comments
 (0)