-
-
Notifications
You must be signed in to change notification settings - Fork 2
Usage
teaminfinitydev edited this page Jun 23, 2025
·
1 revision
use teaminfinitydev\ActivityLogDiscord\Facades\ActivityLogger;
// Simple event logging
ActivityLogger::log('user.action', 'User performed a custom action');
// Detailed logging with subject and causer
ActivityLogger::log(
'order.completed',
'Order #1234 has been completed',
$order, // Subject (the order)
$user, // Causer (who performed the action)
['total' => 99.99, 'items' => 3] // Additional properties
);
// User activity logging
ActivityLogger::logUserLogin($user);
ActivityLogger::logUserLogout($user);
// Model activity logging
ActivityLogger::logModelCreated($post, $user);
ActivityLogger::logModelUpdated($post, $changes, $user);
ActivityLogger::logModelDeleted($post, $user);
// System events
ActivityLogger::logWebAppBootup();
// Test webhook
$success = ActivityLogger::testWebhook();
Add the LogsActivity
trait to your models for automatic tracking:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use teaminfinitydev\ActivityLogDiscord\Traits\LogsActivity;
class Post extends Model
{
use LogsActivity;
// Specify which events to log
protected $logActivity = ['created', 'updated', 'deleted', 'restored'];
// Optional: Customize the display name
public function getDisplayName(): string
{
return $this->title;
}
// Optional: Custom logging conditions
public function shouldLogActivity(string $event): bool
{
// Don't log updates if only timestamps changed
if ($event === 'updated') {
return count($this->getDirty()) > 2; // more than created_at and updated_at
}
return true;
}
// Optional: Additional properties for activity log
public function getActivityLogProperties(string $event): array
{
return [
'category' => $this->category,
'status' => $this->status,
];
}
}
Track user login/logout events automatically:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use teaminfinitydev\ActivityLogDiscord\Facades\ActivityLogger;
class LoginController extends Controller
{
protected function authenticated(Request $request, $user)
{
ActivityLogger::logUserLogin($user);
}
public function logout(Request $request)
{
if (auth()->check()) {
ActivityLogger::logUserLogout(auth()->user());
}
$this->guard()->logout();
$request->session()->invalidate();
return redirect('/');
}
}
Enable bootup messages to monitor when your application starts:
ACTIVITY_LOG_SEND_BOOTUP=true
This will send a message to Discord whenever your web application boots up, useful for monitoring deployments and server restarts.