sarahman / laravel-http-request-api-log by sarahman

This library stores the http request api log into a database table.
1,934
0
1
Package Data
Maintainer Username: sarahman
Maintainer Contact: aabid048@gmail.com (Syed Abidur Rahman)
Package Create Date: 2023-09-01
Package Last Update: 2024-03-25
Language: PHP
License: MIT
Last Refreshed: 2024-04-21 15:00:07
Package Statistics
Total Downloads: 1,934
Monthly Downloads: 324
Daily Downloads: 7
Total Stars: 0
Total Watchers: 1
Total Forks: 2
Total Open Issues: 0

API Log Activity inside Laravel Application

Latest Version on Packagist Build Status Quality Score StyleCI Total Downloads

The sarahman/laravel-http-request-api-log package provides easy to use functionality to log the http api logs in the Laravel application. All the api logs will be stored in the _api_calls table.

You can retrieve all api logs using the Sarahman\HttpRequestApiLog\Models\ApiLog model.

ApiLog::all();

Here's a more advanced example:

...
use Sarahman\HttpRequestApiLog\Traits\WritesHttpLogs;
use Illuminate\Database\Eloquent\Model;

class ApiClient
{
    use LogsActivityWithPivots;
    ...
    ...

    public function __construct()
    {
        ...
        ...
        $this->enableLogging = false;
    }
}

Installation

You can install the package via composer:

composer require sarahman/laravel-http-request-api-log

Next, you must install the service provider:

// app/config/app.php
'providers' => [
    ...
    Sarahman\HttpRequestApiLog\HttpRequestApiLogServiceProvider::class,
];

You can publish the config file with:

php artisan config:publish sarahman/laravel-http-request-api-log

This is the contents of the published config file:

return [
    /*
     * If set to false, no api log will be saved to the database.
     */
    'enabled' => true,

    /*
     * This model will be used to log activity.
     * It should extend Illuminate\Database\Eloquent\Model.
     */
    'api_log_model' => \Sarahman\HttpRequestApiLog\Models\ApiLog::class,

    /*
     * This is the database connection that will be used by the migration and
     * the ApiLog model shipped with this package. In case it's not set
     * Laravel's database.default will be used instead.
     */
    'database_connection' => 'mysql',

    /*
     * This is the name of the table that will be created by the migration and
     * used by the ApiLog model shipped with this package.
     */
    'table_name' => '_api_calls',
];

You can publish the migration with:

php artisan migrate:publish sarahman/laravel-http-request-api-log

Now, you can create the _api_calls table by running the migrations:

php artisan migrate

N.B.: You can disable the api logging to a specific api client using the enableLogging property.

Testing

$ composer test

Security

If you discover any security related issues, please email to this aabid048@gmail.com address instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.