Looking to hire Laravel developers? Try LaraJobs

laravel-sentry maintained by zing

Description
Provides sentry context middleware.
Author
Last update
2026/03/27 02:03 (3.x-dev)
License
Downloads
1 051

Comments
comments powered by Disqus

Laravel Sentry

Requirements

Require Laravel Sentry using Composer:

composer require zing/laravel-sentry

Usage

Add user context

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

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

    // ...
}

Custom user context

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);
    }
}

License

Laravel Sentry is an open-sourced software licensed under the MIT license.