Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

honeybadger-io/nova-honeybadger

Repository files navigation

Honeybadger Tool for Laravel Nova

This package displays Honeybadger errors for resources in Laravel Nova. By default, it shows all of the exceptions each user has encountered in your Laravel app.

screenshot

With custom context and search strings, you can display errors for any resource.

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require honeybadger-io/nova-honeybadger

Next, define your Honeybadger Project ID and Authentication Token inside your config/services.php file, like this:

'honeybadger' => [
    'auth_token' => env('HONEYBADGER_AUTH_TOKEN'),
    'project_id' => env('HONEYBADGER_PROJECT_ID')
]

You can get your Project ID from the URL of your Honeybadger project:

https://app.honeybadger.io/projects/[ID]/faults

Your Authentication Token is available on your Honeybadger profile page (Note: this is different from your project's API key).

Usage

To display the Honeybadger faults that are associated with a given Nova resource, you need to add the Honeybadger Resource Tool to your resource.

To display all errors that are associated with a given Laravel User, all you need to do is add the resource tool to the fields method of your User resource.

For example, in your app/Nova/User.php file:

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        // Your other fields

        new \HoneybadgerIo\NovaHoneybadger\Honeybadger,

    ];
}

This will automatically search Honeybadger for faults with the resource's User ID.

Note: Make sure you also configure Honeybadger to identify users in Laravel.

Defining Custom Context Using Resource Attributes

If you want to search for a different context key/value pair, you can create the resource tool using the fromContextKeyAndAttribute method. This will tell Honeybadger to search for a specific context attribute and use the resource's column as the value.

For example, let's filter our Honeybadger faults by using the resource's email attribute:

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        // Your other fields

        \HoneybadgerIo\NovaHoneybadger\Honeybadger::fromContextKeyAndAttribute('context.user.email', 'email'),

    ];
}

Defining Custom Context

To search your Honeybadger faults using a custom context key and a static value, you may use the fromContextKeyAndValue method. It works similar to withContextKeyAndAttribute, but will use the second parameter as a static string, instead of looking it up as a resource attribute.

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        // Your other fields

        \HoneybadgerIo\NovaHoneybadger\Honeybadger::fromContextKeyAndAttribute('context.user.email', '[email protected]'),

    ];
}

Custom Search String

To get full control over your Honeybadger search string, you may use the fromSearchString method on the resource tool. This let's you define a completely custom search string, that will be used to lookup your Honeybadger faults.

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        // Your other fields

        \HoneybadgerIo\NovaHoneybadger\Honeybadger::fromSearchString('-tag:wip -tag:pending environment:"production"'),

    ];
}

If you only want to append a custom search string to your context attributes, you may use the withSearchString method in combination with the other methods:

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        // Your other fields

        (new \HoneybadgerIo\NovaHoneybadger\Honeybadger)->withSearchString('-environment:"production"'),

    ];
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.