1. Go to this page and download the library: Download litepie/logs 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/ */
litepie / logs example snippets
use Litepie\Logs\Traits\LogsActivity;
class User extends Model
{
use LogsActivity;
protected $fillable = ['name', 'email'];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Litepie\Logs\Traits\LogsActivity;
class User extends Model
{
use LogsActivity;
protected $fillable = ['name', 'email', 'status'];
// Optional: Specify which events to log
protected $logEvents = ['created', 'updated', 'deleted'];
// Optional: Custom log name
protected $logName = 'user-management';
}
class User extends Model
{
use LogsActivity;
protected $fillable = ['name', 'email', 'category_id', 'department_id'];
// Configure which foreign keys should resolve their related model names
protected $resolveRelations = [
'category_id' => 'name', // Will store category name
'department_id' => 'title', // Will store department title
'manager_id' => 'full_name', // Will store manager's full name
];
// Optional: Custom field names for display
protected $fieldNames = [
'category_id' => 'Category',
'department_id' => 'Department',
'manager_id' => 'Manager',
];
public function category()
{
return $this->belongsTo(Category::class);
}
public function department()
{
return $this->belongsTo(Department::class);
}
}
use Litepie\Logs\Facades\ActivityLog;
// Basic logging
ActivityLog::log('User performed action');
// With properties
ActivityLog::withProperties(['key' => 'value'])->log('Action performed');
// With subject and causer
ActivityLog::performedOn($model)
->causedBy($user)
->withProperties(['details' => 'Additional info'])
->log('Model updated');
// Custom log name
ActivityLog::useLog('security')->log('Security event occurred');
use Litepie\Logs\Helpers\ActivityLogger;
// Get activities for a specific model
$activities = ActivityLogger::forModel($user);
// Get activities caused by a user
$userActions = ActivityLogger::causedBy($user);
// Get activities within a date range
$recentActivities = ActivityLogger::betweenDates($startDate, $endDate);
// Get activities by log name
$securityLogs = ActivityLogger::inLog('security');
// Complex queries
$activities = ActivityLog::where('log_name', 'user-management')
->whereNotNull('causer_id')
->with(['subject', 'causer'])
->latest()
->paginate(20);
// Get resolved changes with human-readable names
$activity = ActivityLog::latest()->first();
$changesSummary = $activity->getChangesSummary();
foreach ($changesSummary as $change) {
echo "{$change['field']}: '{$change['old_value']}' → '{$change['new_value']}'\n";
}
// Access raw properties
$properties = $activity->properties;
$ipAddress = $activity->getProperty('ip_address');
// Check for specific changes
if ($activity->hasChanges('email')) {
$oldEmail = $activity->getOldValue('email');
$newEmail = $activity->getNewValue('email');
}
use Litepie\Logs\Helpers\ActivityLogger;
// Get general statistics
$stats = ActivityLogger::getStatistics();
// Get activity trends
$trends = ActivityLogger::getTrends(30); // Last 30 days
// Get top active users
$topUsers = ActivityLogger::getTopUsers(10);
// Get activity by event type
$eventStats = ActivityLogger::getEventStatistics();
class User extends Model
{
use LogsActivity;
// Exclude sensitive fields from logging
protected $logExcept = ['password', 'remember_token'];
// Or specify only fields to
bash
# Export to CSV
php artisan logs:export --format=csv --output=/path/to/export.csv
# Export with filters
php artisan logs:export --format=json --log-name=security --start-date=2024-01-01
# Export for specific user
php artisan logs:export --causer-id=123 --format=pdf
bash
# Show activity statistics
php artisan logs:stats
# Show detailed statistics
php artisan logs:stats --detailed
# Show statistics for specific period
php artisan logs:stats --days=30
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.