Skip to content

Commit

Permalink
Merge pull request #7 from tonypartridge/main
Browse files Browse the repository at this point in the history
Add a note about using the model trait for this to work and support array values
  • Loading branch information
pxlrbt authored Aug 2, 2023
2 parents f795c50 + e8ed7a8 commit bc0c383
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ composer require pxlrbt/filament-activity-log
```

> **Note**
> This plugin only offers a page to show activities related to your model. You need [`spatie/laravel-activitylog`](https://github.com/spatie/laravel-activitylog) installed and configured for it to work.
> This plugin only offers a page to show activities related to your model. You need [`spatie/laravel-activitylog`](https://github.com/spatie/laravel-activitylog) installed and configured for it to work. It is important you are using the `LogsActivity` trait as per [Spatie's docs](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/logging-model-events) for this work as we use the '->activities()' method of the trait.
## Usage


Make sure you use a **custom theme** and the vendor folder for this plugins is published, so that it includes the Tailwind CSS classes.

### Create a page
Expand Down
16 changes: 14 additions & 2 deletions resources/views/pages/list-activities.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,27 @@
$changes = $activityItem->getChangesAttribute();
@endphp
@foreach(data_get($changes, 'attributes', []) as $field => $change)
@php
$oldValue = data_get($changes, "old.{$field}");
$newValue = data_get($changes, "attributes.{$field}");
@endphp
<x-tables::row @class(['bg-gray-100/30' => $loop->even])>
<x-tables::cell width="20%" class="px-4 py-2 align-top">
{{ $this->getFieldLabel($field) }}
</x-tables::cell>
<x-tables::cell width="40%" class="px-4 py-2 align-top break-all !whitespace-normal">
{{ data_get($changes, "old.{$field}") }}
@if(is_array($oldValue))
<pre class="text-xs text-gray-500">{{ json_encode($oldValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}</pre>
@else
{{ $oldValue }}
@endif
</x-tables::cell>
<x-tables::cell width="40%" class="px-4 py-2 align-top break-all !whitespace-normal">
{{ data_get($changes, "attributes.{$field}") }}
@if(is_array($newValue))
<pre class="text-xs text-gray-500">{{ json_encode($newValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}</pre>
@else
{{ $newValue }}
@endif
</x-tables::cell>
</x-tables::row>
@endforeach
Expand Down

0 comments on commit bc0c383

Please sign in to comment.