1. Go to this page and download the library: Download gbhorwood/gander 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/ */
gbhorwood / gander example snippets
\Gbhorwood\Gander\Gander::track()
namespace App\Http\Controllers\api;
use Gbhorwood\Gander\Gander;
class MyController extends BaseController
{
public function getNumber(Request $request, Int $max):JsonResponse
{
$number = $this->generateNumber($max);
Gander::track("number is $number");
return response()->json($number, 200);
}
private function generateNumber(Int $max):Int
{
Gander::track("max is $max");
return rand(1, $max);
}
}
namespace App\Http\Controllers\api;
use Gbhorwood\Gander\Gander;
use App\Jobs\MyJob;
/**
* The controller
*/
public function myController(Request $request): JsonResponse
{
// get the id of this request
$requestId = Gander::requestId();
// pass the request id to the job
dispatch(new MyJob($requestId));
}
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Gbhorwood\Gander\Gander;
/**
* The job
*/
class MyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(String $requestId)
{
Gander::track("a message", $requestId);
}
}