PHP code example of sdkwala / laravel-activity-logger

1. Go to this page and download the library: Download sdkwala/laravel-activity-logger 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/ */

    

sdkwala / laravel-activity-logger example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Sdkwala\ActivityLogger\Traits\LogsActivity;

class Post extends Model
{
    use LogsActivity;
    
    protected $fillable = ['title', 'content'];
}



return [
    'models' => [
        App\Models\Post::class,
        App\Models\User::class,
        App\Models\Comment::class,
    ],
    // ... other config
];

use Sdkwala\ActivityLogger\Models\ActivityLog;

// Get all activity logs
$logs = ActivityLog::all();

// Get logs for a specific model
$postLogs = ActivityLog::where('model_type', Post::class)
    ->where('model_id', $post->id)
    ->get();

// Get logs by event type
$createdLogs = ActivityLog::where('event', 'created')->get();



return [
    // List of model class names to observe for activity logging
    'models' => [
        // App\Models\Post::class,
    ],

    // Events to log
    'events' => [
        'created',
        'updated', 
        'deleted',
    ],

    // Default retention for cleanup command (in days)
    'cleanup_retention_days' => 30,
];
bash
php artisan vendor:publish --provider="Sdkwala\ActivityLogger\ActivityLoggerServiceProvider"
php artisan migrate
bash
php artisan sdkwala:activity-logger:cleanup
bash
php artisan sdkwala:activity-logger:cleanup --days=60