PHP code example of zing / laravel-sentry

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

    

zing / laravel-sentry example snippets


use Zing\LaravelSentry\Middleware\SentryContext;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        SentryContext::class,
    ];

    // ...
}

use Zing\LaravelSentry\Middleware\SentryContext;

class CustomSentryContext extends SentryContext
{
    /**
     * @param \Zing\LaravelSentry\Tests\User $user
     *
     * @return array<string, mixed>|mixed[]
     */
    protected function resolveUserContext(string $guard, \Illuminate\Contracts\Auth\Authenticatable $user): array
    {
        if ($guard === 'api') {
            return [
                'id' => $user->getAuthIdentifier(),
                'username' => $user->username,
            ];
        }

        return parent::resolveUserContext($guard, $user);
    }
}