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();
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,
];
}
}
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('/');
}
}
public function __construct(?string $webhookUrl, string $botName = 'Activity Logger', ?string $avatarUrl = null)
{
$this->client = new Client([
'timeout' => 30,
'connect_timeout' => 10,
'verify' => false, // Disable SSL verification for testing
]);
// Rest of the constructor...
}
try {
// In your DiscordWebhookService.php
Log::debug('Attempting to connect to Discord webhook', [
'webhook_url' => $this->maskWebhookUrl($this->webhookUrl),
]);
$response = $this->client->post($this->webhookUrl, [
// your existing options
'debug' => true, // Add this to see detailed request/response info
]);
} catch (RequestException $e) {
Log::error('Discord webhook error details', [
'request_exception_details' => method_exists($e, 'getHandlerContext') ? $e->getHandlerContext() : 'Not available',
]);
}
🚀 System Bootup
Web application started successfully
Details:
Environment: production
PHP Version: 8.2.0
Laravel Version: 10.0.0
Memory Usage: 32.5 MB
Server Time: 2024-01-15 14:30:22
bash
php artisan queue:work
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.