PHP code example of atatus / laravel-atatus

1. Go to this page and download the library: Download atatus/laravel-atatus 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/ */

    

atatus / laravel-atatus example snippets



// In config/app.php

'providers' => [
  /*
   * Application Service Providers...
   */
    Atatus\Middleware\AtatusLaravelServiceProvider::class,
];


// In App/Http/Kernel.php

protected $middleware = [
  /*
   * The application's global HTTP middleware stack.
   *
   * These middleware are run during every request to your application.
   */
   \Atatus\Middleware\AtatusLaravel::class,
];


// In App/Http/Kernel.php

protected $middlewareGroups = [
  /**
   * The application's API route middleware group.
   */
   'api' => [
        //
        \Atatus\Middleware\AtatusLaravel::class,
    ],
];


// In config/atatus.php

return [
    'logBody' => true,
    // 'debug' => false,
    // 'configClass' => 'MyApp\\MyConfigs\\CustomAtatusConfig'
];

return [
    'logBody' => true,
    'debug' => false,
    'configClass' => 'MyApp\\MyConfigs\\CustomAtatusConfig'
];

namespace MyApp\MyConfigs;

class CustomAtatusConfig
{

    public function maskRequestBody($body) {
      return $body;
    }

    public function maskResponseBody($body) {
      return $body;
    }

    public function identifyUserId($request, $response) {
      if (is_null($request->user())) {
        return null;
      } else {
        $user = $request->user();
        return $user['id'];
      }
    }

    public function identifyCompanyId($request, $response) {
      return "comp_acme_corporation";
    }

}


return [
    'logBody' => true,
    'debug' => false,
    'configClass' => 'MyApp\\MyConfigs\\CustomAtatusConfig'
]

bash
$ php artisan vendor:publish --provider="Atatus\Middleware\AtatusLaravelServiceProvider"