How to setup and configure laravel telescope in existing projects

4 months ago SETHA THAY 412
How to setup and configure laravel telescope in existing projects

In this article, we are going to do an experiment showcase of the laravel telescope for our existing project NestCode GEO which includes step by step of installation processes and configurations needed to fulfill our scenario for NestCode GEO. The goal is to use the laravel telescope as a debugging and monitoring tool to provide useful debug information which is essential for building bug-free applications.

In laravel's official website laravel telescope is well-known as debugging assistant for any application using the laravel framework from version 5.7. Telescope provides insight into the requests coming into the application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more.

INSTALLATION

First, using composer to install the telescope package into your existing project

composer require laravel/telescope "^3.0"

Next, publish telescope assets using the telescope:install using artisan command

php artisan telescope:install

Export telescope migration file using the below command

php artisan vendor:publish --tag=telescope-migrations

Copied Directory [\vendor\laravel\telescope\src\Storage\migrations] To [\database\migrations]
Publishing complete.

Once getting the telescope migration file, you may wish you run it separately to create the table in the database

php artisan migrate --path=/database/migrations/2018_08_08_100000_create_telescope_entries_table.php

Migrating: 2018_08_08_100000_create_telescope_entries_table
Migrated:  2018_08_08_100000_create_telescope_entries_table (0.47 seconds)

As a result, you can check in the database if it creates these three tables telescope_entriestelescope_entries_tagstelescope_monitoring

In the local environment, we can access the dashboard of the telescope from this route /telescope

CONFIGURATION

The main purpose of Telescope is to make a wonderful companion to the local Laravel development environment. However, when deploying telescope to production there are a few more steps to configure for securities that only assigned permission users to have access to the telescope dashboard.

Once deploying your application to production, just in case telescope classes have not been discovered you can follow the below command to try.

composer dump-autoload

In order to authorize the dashboard of the telescope in production, Within the app/Providers/TelescopeServiceProvider.php file, there is an authorization gate definition. This authorization gate controls access to Telescope in non-local environments (Production). In our context application, we have changed to the following

- Only user that is super admin who can use the telescope dashboard
- We use Session in the gate control since our back-end use session to identify a logged-in user

protected function gate()
{
    /*Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
        //
        ]);
    });*/
    Gate::define('viewTelescope', function ($user = null) {
       return Session::get('admin_is_superadmin') == 1;
    });
}

Please note that the environment key APP_ENV have to change to production

how-to-setup-and-configure-laravel-telescope-in-existing-projects-telescope

THANK YOU, Find Us @
Facebook
Telegram
Twitter
LinkedIn


About author

Author Profile

SETHA THAY

Software Engineer & Project Manager. I am willing to share IT knowledge, technical experiences and investment to financial freedom. Feel free to ask and contact me.


DigitalOcean Referral Badge

Scroll to Top