hsndmr/cappadocia-viewer-for-laravel

Cappadocia Viewer for Laravel

1.1.0 2023-08-05 18:09 UTC

README

Cappadocia Viewer for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

Prior to installing this package, ensure that you have already installed Cappadocia Viewer

You can install the package via composer:

composer require hsndmr/cappadocia-viewer-for-laravel --dev

You can publish the config file with:

php artisan vendor:publish --tag="cappadocia-viewer"

This is the contents of the published config file:

return [
    'server_url'    => env('CAPPADOCIA_VIEWER_SERVER_URL', 'http://127.0.0.1:9091'),
    'timeout'       => env('CAPPADOCIA_VIEWER_TIMEOUT', 3),
    'enabled'       => env('CAPPADOCIA_VIEWER_ENABLED', true),
    'watch_logs'    => env('CAPPADOCIA_VIEWER_WATCH_LOGS', true),
    'watch_jobs'    => env('CAPPADOCIA_VIEWER_WATCH_JOBS', false),
    'watch_queries' => env('CAPPADOCIA_VIEWER_WATCH_QUERIES', false),
];

Usage

Showing Queries

You can show queries by using cappadocia helper function.

    cappadocia()->watchQueries();
    User::latest()->first();
    cappadocia()->stopWatchingQueries();
    
    // This query will not be shown in the viewer
    User::first()->first();
Cappadocia Viewer for Laravel

If you want to show all queries, you can add CAPPADOCIA_VIEWER_WATCH_QUERIES=true to your .env file.

Showing Jobs

You can show jobs by using cappadocia helper function.

cappadocia()->watchJobs();
CappadociaViewerJob::dispatchSync('viewer');
cappadocia()->stopWatchingJobs();

// This job will not be shown in the viewer
CappadociaViewerJob::dispatchSync('another viewer');
Cappadocia Viewer for Laravel

If you are utilizing Laravel Horizon, you can insert CAPPADOCIA_VIEWER_WATCH_JOBS=true into your .env file. This will enable you to view all jobs in the viewer

CappadociaViewerJob::dispatch('viewer');

Showing Logs

Logs are shown by default. If you want to disable it, you can add CAPPADOCIA_VIEWER_WATCH_LOGS=false to your .env file.

Log::info('This log will be shown in the viewer');
Cappadocia Viewer for Laravel

Showing Requests

If you want to show requests, you can add CAPPADOCIA_VIEWER_WATCH_REQUESTS=true to your .env file. After that, you can see all requests in the viewer.

Cappadocia Viewer for Laravel

Custom Messages

If you want to show custom messages, you can use cappadocia helper function.

cappadocia('This is custom message')
    ->send([
        'custom' => 'data',
    ]);

cappadocia('This is custom message with Badge')
    ->setBadge('Badge')
    ->send([
        'custom' => 'data',
    ]);
Cappadocia Viewer for Laravel

Disabling Cappadocia Viewer

To disable the Cappadocia Viewer, you can include CAPPADOCIA_VIEWER_ENABLED=false in your .env file. This could be particularly useful if you wish to disable it within a testing environment.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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