Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Spatie Activitylog Ui Laravel Package

mayaram/spatie-activitylog-ui

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the package via Composer:
    composer require mayaram/spatie-activitylog-ui
    
  2. Publish assets and config:
    php artisan vendor:publish --provider="Mayaram\ActivityLogUI\ActivityLogUIServiceProvider" --tag="activity-log-ui-config"
    php artisan vendor:publish --provider="Mayaram\ActivityLogUI\ActivityLogUIServiceProvider" --tag="activity-log-ui-assets"
    
  3. Add routes in routes/web.php:
    use Mayaram\ActivityLogUI\Http\Controllers\ActivityLogController;
    Route::middleware(['auth'])->group(function () {
        Route::get('/activity-log', [ActivityLogController::class, 'index'])->name('activity-log.index');
    });
    
  4. Run migrations (if not already done for Spatie's ActivityLog):
    php artisan migrate
    

First Use Case

  • Visit /activity-log after authentication.
  • Use the default dashboard to view recent activities in a table format.
  • Apply filters (e.g., user:admin, event:created) to narrow results.

Implementation Patterns

Core Workflows

  1. Dashboard Customization

    • Override the default dashboard by publishing views:
      php artisan vendor:publish --provider="Mayaram\ActivityLogUI\ActivityLogUIServiceProvider" --tag="activity-log-ui-views"
      
    • Extend resources/views/vendor/activity-log-ui/dashboard.blade.php to add custom widgets or layouts.
  2. Filtering & Search

    • Leverage the built-in filter panel for dynamic queries. Example:
      // In a custom controller method
      $query = ActivityLog::query();
      if ($request->filled('user')) {
          $query->where('properties->user', 'like', "%{$request->user}%");
      }
      return ActivityLogController::applyFilters($query, $request)->get();
      
  3. Real-Time Updates

    • Use Laravel Echo/Pusher to push activity log updates to clients:
      // In your frontend JS
      Echo.channel('activity-log-updates')
          .listen('ActivityUpdated', (e) => {
              // Refresh UI or show toast
          });
      
  4. Export Integration

    • For Excel/PDF exports, install dependencies:
      composer require maatwebsite/excel dompdf/laravel-dompdf
      
    • Use the built-in export buttons in the UI or trigger via API:
      $export = new \Mayaram\ActivityLogUI\Exports\ActivityLogExport($query);
      return Excel::download($export, 'activity_log.xlsx');
      

Integration Tips

  • Authorization: Use the can:view-activity-log gate or middleware:
    Gate::define('view-activity-log', function ($user) {
        return $user->isAdmin(); // Custom logic
    });
    
  • ActivityLog Events: Extend Spatie’s events to include custom metadata:
    Activity::log('custom.event', $subject)
        ->withProperties(['custom_field' => 'value']);
    
  • API Access: Expose filtered logs via a custom API endpoint:
    Route::get('/api/activity-log', [ActivityLogController::class, 'apiIndex']);
    

Gotchas and Tips

Pitfalls

  1. Database Schema Mismatch

    • Ensure your activity_log table matches Spatie v5 schema. Run:
      php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"
      php artisan migrate
      
    • Error: Column 'properties' not found → Re-run migrations or manually add missing columns.
  2. Caching Issues

    • Real-time counts rely on Laravel cache. Clear cache if counts appear stale:
      php artisan cache:clear
      
    • Tip: Disable caching for development:
      ACTIVITY_LOG_UI_CACHE=false
      
  3. Alpine.js Conflicts

    • If Alpine.js scripts conflict with other packages, isolate the UI:
      <div x-data="{ open: false }" x-show="open" @click.away="open = false">
          <!-- Filter panel -->
      </div>
      
  4. Export Dependencies

    • Forgetting to install maatwebsite/excel or dompdf/laravel-dompdf will break export buttons.
    • Fix: Add to composer.json and run composer install.

Debugging

  • Query Logs: Enable Laravel query logging to debug filter issues:
    DB::enableQueryLog();
    $query = ActivityLog::query()->where(...);
    dd(DB::getQueryLog());
    
  • ActivityLog Events: Verify events are logged correctly:
    Activity::log('test.event', $model)->withProperties(['debug' => true]);
    
    Check the database or use Tinker:
    php artisan tinker
    >> \Spatie\Activitylog\Models\Activity::latest()->first()->properties;
    

Extension Points

  1. Custom Filters

    • Add dynamic filters via a service provider:
      public function boot()
      {
          ActivityLogUI::extendFilters(function ($builder) {
              $builder->addFilter('status', 'Status', 'select', ['draft', 'published']);
          });
      }
      
  2. Timeline View

    • Override the timeline template:
      php artisan vendor:publish --provider="Mayaram\ActivityLogUI\ActivityLogUIServiceProvider" --tag="activity-log-ui-views"
      
    • Extend resources/views/vendor/activity-log-ui/timeline.blade.php.
  3. Analytics Dashboard

    • Add custom charts using Chart.js or Laravel Charts:
      // In your dashboard blade
      <canvas id="activityChart"></canvas>
      <script>
          new Chart(document.getElementById('activityChart'), {
              type: 'bar',
              data: {
                  labels: @json($labels),
                  datasets: [{
                      label: 'Activity Count',
                      data: @json($data)
                  }]
              }
          });
      </script>
      
  4. Middleware Hooks

    • Intercept requests to modify queries or enforce policies:
      public function handle($request, Closure $next)
      {
          if ($request->user()->cannot('view-activity-log')) {
              abort(403);
          }
          return $next($request);
      }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium