Skip to content

Commit

Permalink
Merge pull request #110 from denydias/details-field
Browse files Browse the repository at this point in the history
Add support for activity details.
  • Loading branch information
jeremykenedy committed Dec 18, 2020
2 parents d445691 + 0786734 commit 06b5fa6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Laravel logger is an activity event logger for your Laravel or Lumen application
|Routing Events can recording using middleware|
|Records activity timestamps|
|Records activity description|
|Records activity details (optional)|
|Records activity user type with crawler detection.|
|Records activity Method|
|Records activity Route|
Expand Down Expand Up @@ -218,20 +219,25 @@ When using the trait you can customize the event description.
To use the trait:
1. Include the call in the head of your class file:

```php
use jeremykenedy\LaravelLogger\App\Http\Traits\ActivityLogger;
```
```php
use jeremykenedy\LaravelLogger\App\Http\Traits\ActivityLogger;
```

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

```php
use ActivityLogger;
```
```php
use ActivityLogger;
```

3. You can record the activity my calling the traits method:
```
ActivityLogger::activity("Logging this activity.");
```
```
ActivityLogger::activity("Logging this activity.");
```

Or as bellow to include extended activity details:
```
ActivityLogger::activity("Logging this activity.", "Additional activity details.");
```

### Routes
##### Laravel Activity Dashbaord Routes
Expand Down
7 changes: 5 additions & 2 deletions src/App/Http/Traits/ActivityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ trait ActivityLogger
/**
* Laravel Logger Log Activity.
*
* @param string $description
* @param null $description
* @param null $details
*
* @return void
*/
public static function activity($description = null)
public static function activity($description = null, $details = null)
{
$userType = trans('LaravelLogger::laravel-logger.userTypes.guest');
$userId = null;
Expand Down Expand Up @@ -61,6 +62,7 @@ public static function activity($description = null)

$data = [
'description' => $description,
'details' => $details,
'userType' => $userType,
'userId' => $userId,
'route' => Request::fullUrl(),
Expand Down Expand Up @@ -94,6 +96,7 @@ private static function storeActivity($data)
{
config('laravel-logger.defaultActivityModel')::create([
'description' => $data['description'],
'details' => $data['details'],
'userType' => $data['userType'],
'userId' => $data['userId'],
'route' => $data['route'],
Expand Down
3 changes: 3 additions & 0 deletions src/App/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Activity extends Model
*/
protected $fillable = [
'description',
'details',
'userType',
'userId',
'route',
Expand All @@ -69,6 +70,7 @@ class Activity extends Model

protected $casts = [
'description' => 'string',
'details' => 'string',
'user' => 'integer',
'route' => 'string',
'ipAddress' => 'string',
Expand Down Expand Up @@ -134,6 +136,7 @@ public static function rules($merge = [])
return array_merge(
[
'description' => 'required|string',
'details' => 'nullable|string',
'userType' => 'required|string',
'userId' => 'nullable|integer',
'route' => 'nullable|'.$route_url_check,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function up()
Schema::connection($connection)->create($table, function (Blueprint $table) {
$table->increments('id');
$table->longText('description');
$table->longText('details')->nullable();
$table->string('userType');
$table->integer('userId')->nullable();
$table->longText('route')->nullable();
Expand Down
5 changes: 5 additions & 0 deletions src/resources/lang/de/laravel-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'id' => 'Aktivitätslog ID:',
'ip' => 'IP Adresse',
'description' => 'Beschreibung',
'details' => 'Einzelheiten',
'userType' => 'Nutzertyp',
'userId' => 'Nutzer ID',
'route' => 'Route',
Expand All @@ -107,6 +108,10 @@
'userCreatedAt' => 'Erstellt',
'userUpdatedAt' => 'Bearbeitet',
],

'fields' => [
'none' => 'Keiner',
],
],

],
Expand Down
5 changes: 5 additions & 0 deletions src/resources/lang/en/laravel-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'id' => 'Activity Log ID:',
'ip' => 'Ip Address',
'description' => 'Description',
'details' => 'Details',
'userType' => 'User Type',
'userId' => 'User Id',
'route' => 'Route',
Expand All @@ -107,6 +108,10 @@
'userCreatedAt' => 'Created',
'userUpdatedAt' => 'Updated',
],

'fields' => [
'none' => 'None',
],
],

],
Expand Down
5 changes: 5 additions & 0 deletions src/resources/lang/fr/laravel-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
'id' => 'Activité Id :',
'ip' => 'Adresse Ip',
'description' => 'Description',
'details' => 'Détails',
'userType' => 'Type Utilisateur',
'userId' => 'Id Utilisateur',
'route' => 'Route',
Expand All @@ -105,6 +106,10 @@
'userCreatedAt' => 'Créé le',
'userUpdatedAt' => 'Actualisé le',
],

'fields' => [
'none' => 'Aucun',
],
],

],
Expand Down
2 changes: 2 additions & 0 deletions src/resources/views/logger/activity-log-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
<dd>{{$activity->id}}</dd>
<dt>{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.labels.description') !!}</dt>
<dd>{{$activity->description}}</dd>
<dt>{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.labels.details') !!}</dt>
<dd>@if($activity->details){{$activity->details}}@else{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.fields.none') !!}@endif</dd>
<dt>{!! trans('LaravelLogger::laravel-logger.drilldown.list-group.labels.route') !!}</dt>
<dd>
<a href="@if($activity->route != '/')/@endif{{$activity->route}}">
Expand Down

0 comments on commit 06b5fa6

Please sign in to comment.