1. Go to this page and download the library: Download prahsys/laravel-api-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/ */
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Prahsys\ApiLogs\Http\Middleware\GuzzleApiLogMiddleware;
$stack = HandlerStack::create();
$stack->push(app(GuzzleApiLogMiddleware::class));
$client = new Client([
'handler' => $stack,
'base_uri' => 'https://api.example.com',
'timeout' => 30,
]);
// Get your existing handler stack
$stack = $existingClient->getConfig('handler');
// Add API logging middleware
$stack->push(app(GuzzleApiLogMiddleware::class));
use Prahsys\ApiLogs\Models\HasApiLogItems;
class User extends Model
{
use HasApiLogItems;
// ... model code
}
// Get all API requests for a model
$user = User::find(1);
$requests = $user->apiLogItems;
// Get the latest API request for a model
$latestRequest = $user->latestApiLogItem();
// Get all models associated with an API request
$apiLogItem = ApiLogItem::where('request_id', $requestId)->first();
$users = $apiLogItem->getRelatedModels(User::class)->get();
// Example: Track all models affected by a single API request
$apiLogItem = ApiLogItem::where('request_id', 'abc-123-def')->first();
// Get all users modified in this request
$affectedUsers = $apiLogItem->getRelatedModels(User::class)->get();
// Get all orders created/updated in this request
$affectedOrders = $apiLogItem->getRelatedModels(Order::class)->get();
// Get all affected models regardless of type
$allAffectedModels = $apiLogItem->relatedModels; // Returns collection of all associated models
// Example output for debugging or audit purposes
foreach ($allAffectedModels as $model) {
echo "Modified {$model->getMorphClass()}: ID {$model->id}";
}
'users.*.email' // Matches users.1.email, users.john.email, etc.
'**.card.number' // Matches card.number anywhere in the data structure
'**.password' // Matches password fields at any depth
// Traditional specific paths
\Prahsys\ApiLogs\Redactors\DotNotationRedactor::class => [
'paths' => ['request.body.users.0.password', 'request.body.users.1.password'],
]
// Using single wildcards
\Prahsys\ApiLogs\Redactors\DotNotationRedactor::class => [
'paths' => ['request.body.users.*.password'],
]
// Using deep wildcards for complex nested data
\Prahsys\ApiLogs\Redactors\DotNotationRedactor::class => [
'paths' => ['**.password', '**.card.number', '**.ssn'],
]
bash
# Run model pruning manually
php artisan model:prune
# Schedule in your app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('model:prune')->daily();
}
env
# Retain database references for 1 year (default)
API_LOGS_TTL_HOURS=8760
# Or configure in config file
'database' => [
'pruning' => [
'ttl_hours' => 24 * 365, // 365 days
],
],
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.