PHP code example of yared / laravel-activity-tracker

1. Go to this page and download the library: Download yared/laravel-activity-tracker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yared / laravel-activity-tracker example snippets


use Yared\ActivityTracker\Facades\Activity;

// In a controller
Activity::track(auth()->user(), "created order #2001");

// With extra properties
Activity::track(auth()->user(), "exported report", [
    'format' => 'pdf',
    'rows' => 150,
]);

use Illuminate\Database\Eloquent\Model;
use Yared\ActivityTracker\Traits\LogsActivity;

class Order extends Model
{
    use LogsActivity;
}

use Yared\ActivityTracker\Models\ActivityLog;

// Latest activities
$activities = ActivityLog::latest()->take(50)->get();

// For a specific user
$activities = ActivityLog::forUser($userId)->latest()->get();

// Last 7 days
$activities = ActivityLog::recent(7)->get();

// app/Http/Kernel.php
protected $middlewareAliases = [
    'activity.track' => \Yared\ActivityTracker\Middleware\TrackRequest::class,
];
bash
php artisan vendor:publish --tag=activity-config
php artisan migrate
bash
# Use config value (default: 90 days)
php artisan activity:clean

# Custom days
php artisan activity:clean --days=30