Technology

How to Get Started with Laravel Telescope in the App

Laravel

Laravel Telescope is a new debug assistant for the Laravel framework which is free, open-source and licensed under the MIT license. It was first publicized at Laracon AU, and then its beta was released. 

Whenever you write code, manual debugging of the error in your application is very hard. That’s where the telescope helps by giving access to the requests entering into your application, log entries, exceptions, model watch, mail, database queries, catch, queued jobs, redis, scheduled tasks, and more in one place.

Thus, you can exploit Laravel Telescope to debug your requests, databases, exceptions, cache, and much more in real-time by entering into a definite route in your local environment.

Why Laravel Telescope is important in the app development process?

  • With the Laravel Telescope, expert Laravel developers can avail actionable insights which surely benefit the application, log entries, database queries, etc.
  • It allows you to observe the collaboration of different components of your app.
  • Also, it helps to find out website pages that are working correctly and the ones which need debugging.

How to install Laravel Telescope?

Make sure that Laravel 5.7.7 is installed before you start installing Laravel telescope. If you have not installed it yet and are looking for a fresh install, you may check out the Laravel 5.7’s installation guide. Alternatively, if you have Laravel installed already, you can upgrade.

Now, to install Laravel telescope, you should run:

composer require laravel/telescope –dev

However, if you don’t have the bcmath extension installed, you may get following error:

Problem 1

 – moontoast/math 1.1.2 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
– moontoast/math 1.1.1 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
– moontoast/math 1.1.0 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
– laravel/telescope v0.1.5 requires moontoast/math ^1.1 -> satisfiable by moontoast/math[1.1.0, 1.1.1, 1.1.2].
– Installation request for laravel/telescope ^0.1.5 -> satisfiable by laravel/telescope[v0.1.5].

To quickly fix this, simply run:

sudo apt install php7.2-bcmath
sudo service apache2 restart

If you have PHP 7.1, you should use php7.1-bcmath.

Now, again run, composer require laravel/telescope –dev.

Once the installation is done, you can move prepare the assets, config files, and database. For this run; 

php artisan telescope:install
php artisan migrate

Now comes, configuring Laravel Telescope:

After the installation, open the route /telescope in your browser. This route can be changed in the config/telescope.php file as well. This file allows you to configure Telescope. Other important options are:

path

In the path, which is there in your app, Telescope will be accessible. Don’t incorporate slashes. Here, the telescope is the default value.

storage

At this place, Telescope will store the data. You can’t change this value where the database is the only supported value.

driver

This will use your default database connection.

limit

This decides how much data Telescope will store for the things you will debug. And 100 is the default value here.

Verifying who has access to Telescope

Any user can access Telescope in the local environment whereas in other environments, only selected users can have the right to access Telescope. If you have to configure the access in production, then you need to go to app/Providers/TelescopeServiceProvider.php and find the gate function.

protected function gate()
{
      Gate::define(‘viewTelescope’, function ($user) {
        return in_array($user->email, [
                //
            ]);
        });
}

You can add a list of emails, and then these users can access Telescope. You can also use environment variables and IDs, because:

  • You can have dissimilar emails locally or in production.
  • You may alter your email and then change your code.
  • It’s like storing access tokens in the code, particularly if you’re using version control.

While using IDs, the function needs to be modified which looks like this;

protected function gate()
{
    Gate::define(‘viewTelescope’, function ($user) {
    $ids = env(‘TELESCOPE_USERS’, ”);
    $ids = explode(‘,’, $ids);
    return in_array($user->id, $ids);
    });
}

Now, to set your environment variable, use the following code separating them with a comma,

TELESCOPE_USERS=1,2

Don’t add spaces between your IDs.

Thus, installation and setup of Laravel Telescope are done. Now, you would be automatically directed to the dashboard where you can see the tabs on the left side of the listing pages with various types of features. Some of these features are given as follows;

Requests

With this feature, you can access various types of HTTP requests that usually come into your application. To get additional information on each request, you can click on the eye icon. You can also view associated data from other parameters with each request. And the best thing is that the extra information is not limited to the queries.

Queries

This feature is useful to list all the queries related to the database. With this page, it gets easy to set a benchmark for the questions obtained during a specified time.

Schedule

The Scheduler allows you to define a broad variety of data. The Schedule page also gives you access to various commands for a number of assignments. After accessing the schedule, you can track the status of each access.  

Mails and other Notifications

The mail page shows you the list of sent emails as well as the names of the recipients. The notification page illustrates a category of notifications and the channels on which they are developed. You can also have caches along with updates and misses as well as the requests that triggered it along with other components. You can also access the Redis page that is similar to the cache page.

Wrapping up:

Thus, Laravel Telescope can run locally by using built-in authorization and tools while securing confidential data. It allows you to access similar data from various angles. Being a great debugging tool, it offers you robust tagging and sorting. Lastly, Laravel Telescope is surely helpful for directly facilitating quicker resolutions to your clients.

Related posts
Technology

Is It Legal to Make Money from Bitcoin?

Technology

How Long Does a Bitcoin Transaction Take?

Technology

What Is Behind Bitcoin And How It Works?

Technology

How Much Is .001 Bitcoin Worth?