PHP code example of plopster / trace-code-maker

1. Go to this page and download the library: Download plopster/trace-code-maker 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/ */

    

plopster / trace-code-maker example snippets



Schema::create('trace_codes', function (Blueprint  $table) {

$table->uuid('id')->primary();

$table->string('trace_code')->unique()->index('trace-code-index');

$table->string('service')->index('restaurant-service-index');

$table->string('http_code')->index('restaurant-http-index');

$table->string('method')->index('restaurant-method-index');

$table->string('class')->index('restaurant-class-index');

$table->string('description');

$table->timestamp('timestamp');

});



namespace  App\Providers;

  

use Illuminate\Support\ServiceProvider;

use Plopster\TraceCodeMaker\TraceCodeMaker;

  

class  TraceCodeMakerServiceProvider  extends  ServiceProvider

{

/**

* Register services.

*/

public  function  register(): void

{

$this->app->singleton('tracecodemaker', function ($app) {

return  new  TraceCodeMaker();

});

}

  

/**

* Bootstrap services.

*/

public  function  boot(): void

{

//

}

}



'providers' => [

// Other Service Providers
App\Providers\TraceCodeMakerServiceProvider::class,
],



namespace  App\Facades;

  

use Illuminate\Support\Facades\Facade;

  

class  TraceCodeMaker  extends  Facade

{

protected  static  function  getFacadeAccessor()

{

return  'tracecodemaker';

}

}



'aliases' => [

// Other Facades

  

'TraceCodeMaker' => App\Facades\TraceCodeMaker::class,

],



use  TraceCodeMaker;

  

$service  =  'ReservationService';

$httpCode  =  500;

$methodName  =  'reserveTable';

$className  =  'TableController';

  

$response  =  TraceCodeMaker::fetchOrCreateTraceCode($service, $httpCode, $methodName, $className);

  

if ($response['error']) {

// Handle error

echo  $response['message'];

} else {

// Use the trace code

echo  "Trace Code: "  .  $response['traceCode'];

}

bash

php  artisan  migrate