Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript React React Vue Vue Protocol Protocol
  • General
  • Installation
  • Censoring collected data
  • Ignoring collected data
  • Flare daemon
  • Laravel Octane
  • Laravel Vapor
  • Errors
  • Introduction
  • Customise error report
  • Customising error grouping
  • Linking to errors
  • Logs
  • Introduction
  • Levels
  • With errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and span events
  • Data Collection
  • Application info
  • Cache events
  • Console commands
  • Custom context
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Jobs and queues
  • Laravel context
  • Livewire
  • Queries
  • Redis commands
  • Requests
  • Server info
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Laravel Flare V2
  • Laravel Flare V1
  • Ignition

Identifying users

When a user logs in to your Laravel application and an error or trace occurs, helpful information about the user is sent to Flare.

By default, the following attributes are sent:

  • id
  • email
  • name (or full_name, fullName, username, in that order)

The defaults try a handful of common property names on the user object so most apps work out of the box. If your model uses different property names, see Customising user data below.

Sending extra attributes

When you want to send additional attributes alongside the defaults, implement a toFlare method on your user model. The returned array is merged into the user attributes:

class User extends Authenticatable
{
    public function toFlare(): array
    {
        return [
            'team_id' => $this->team_id,
            'plan' => $this->subscription?->plan_name,
        ];
    }
}

For most applications, this is all you need.

Customising user data

When the defaults don't fit (different property names, computed fields, an entirely different user object), extend LaravelUserAttributesProvider and override the methods you need. The user is available as $this->user inside each method:

namespace App\Flare;

use Spatie\LaravelFlare\AttributesProviders\LaravelUserAttributesProvider;

class CustomUserAttributesProvider extends LaravelUserAttributesProvider
{
    public function id(): string|int|null
    {
        return $this->user->uuid;
    }

    public function fullName(): ?string
    {
        return "{$this->user->first_name} {$this->user->last_name}";
    }

    public function email(): ?string
    {
        return $this->user->work_email;
    }

    public function attributes(): array
    {
        return [
            'team_id' => $this->user->team_id,
        ];
    }
}

Bind it in the container so the package picks up your subclass anywhere it constructs a user attributes provider:

// AppServiceProvider::register()
$this->app->bind(
    \Spatie\LaravelFlare\AttributesProviders\LaravelUserAttributesProvider::class,
    \App\Flare\CustomUserAttributesProvider::class,
);

Sending no user data

To send no user data at all, bind the LaravelUserAttributesProvider to the framework-agnostic EmptyUserAttributesProvider that ships with flare-client-php. It returns null (or an empty array) for every field:

$this->app->bind(
    \Spatie\LaravelFlare\AttributesProviders\LaravelUserAttributesProvider::class,
    \Spatie\FlareClient\AttributesProviders\EmptyUserAttributesProvider::class,
);

For more on the underlying contract, see the PHP attribute providers docs.

Glows Jobs and queues
  • On this page
  • Sending extra attributes
  • Customising user data
  • Sending no user data

Catch errors and fix slowdowns with Flare, the full-stack application monitoring platform for Laravel, PHP & JavaScript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Insights
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by
Flare