PHP code example of maksudur-dev / laravel-logpilot
1. Go to this page and download the library: Download maksudur-dev/laravel-logpilot 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/ */
activity('user_login');
// With details
activity('profile_updated', $user, 'User updated their profile photo');
// With array message (automatically cast to JSON)
activity('api_response', null, [
'status' => 'success',
'data' => ['id' => 1]
]);
// Full control
activity(
action: 'withdraw_request',
model: $user,
message: 'Gateway timeout',
level: 'error',
meta: ['amount' => 500]
);
use LaravelLogPilot\Traits\LogsActivity;
class Order extends Model
{
use LogsActivity;
}
// Now you can do:
$order->logActivity('shipped', 'Order has been shipped to customer');
// Retrieve logs for this model:
$logs = $order->activities;
use LaravelLogPilot\Services\ActivityLogger;
class PaymentService
{
public function __construct(protected ActivityLogger $logger) {}
public function process()
{
$this->logger->log('payment_started');
}
}
activity_group('checkout_flow_001');
activity('cart_validated');
activity('payment_processing');
activity('order_created'); // All will share log_id: checkout_flow_001