Tips on using Laravel Telescope in Production

The Telescope documentation does not seem complete. There are several hoops, troubleshooting, and errors one might experience getting Telescope up and running in a production environment. Here’s a handful of things you might want to do or check if you run into any problems.

  • Run $ php artisan config:cache
  • Remove Authorize::class from config/telescope middleware section
  • Ignore migrations if not using the telescope migrations or if it’s giving you trouble
  • Make sure you’re using the correct middleware (default: web)
  • Manually include TelescopeServiceProvider in config/app (this issue seems common)
  • Make sure you don’t have “laravel/telescope” under the don’t discover section of your composer.json file
  • (Heroku) Make sure you install the php extension bcmath through composer
  • If entries aren’t being recorded check the register method of your TelescopeServiceProvider

Run $ php artisan config cache

Just a good idea to clear the config cache if you run into problems

Ignore Migrations

In App/Providers/AppServiceProvider class register() method you can add the following to ignore Telescope migrations.

use Laravel\Telescope\Telescope;
public function register()
    {
            Telescope::ignoreMigrations();
    }

It’s particularly helpful if for some reason Laravel thinks you need to remigrate telescope every time.

Remove Authorize::class from config/telescope

The Authorize Middleware restricts any access to telescope except on local env.  If your TelescopeServiceProvider is properly defined, the callback and the viewTelescope gate will be defined there.

Make sure you’re using the correct middleware

The middleware option you will set will be applied to each and every route. In the future, you’d want to add auth middleware so that it can be access after login.

Manually include TelescopeServiceProvider in config/app

I saw this issue appear the most in my search. Though it didn’t solve my problem as it should autoload in recent versions.

Config\app.php

'provider' => [
    ...
    App\Providers\TelescopeServiceProvider::class,
]

Make sure you don’t have “laravel/telescope” under the don’t discover section of your composer.json file

Another common mistake people have made. If you don’t remember adding it there then it’s probably not. But if you have double check just for good measure.


    "extra": {
        "laravel": {
            "dont-discover": [

            ]
        }
    },

Make sure you install the php extension bcmath through composer

This is for Heroku users or Heroku like services. Telescope requires bcmath. Add
“ext-bcmath”: “*”, to your composer require.

If entries aren’t being recorded check the register method of your TelescopeServiceProvider

In your .env file you add TELESCOPE_KEY = true. And in your telescopeServiceProvider’s register method update this,

Telescope::filter(function (IncomingEntry $entry) {
    if ( $this->app->isLocal()) {
        return true;
}

// to this

Telescope::filter(function (IncomingEntry $entry) {
    if (env('TELESCOPE_KEY', false) | $this->app->isLocal()) {
        return true;
}

Conclusion

I personally experienced a database error when running $ php artian telescope:install. I had to copy the migration file “xxx_create_telescope_entries_table” from “vendor/laravel/telescope” and ran the migration before running telescope:install again. And that worked. This is for Laravel 6.2 and Telescope 2.1.

Good luck!

2 thoughts on “Tips on using Laravel Telescope in Production”

  1. Im getting 403 forbidden in AWS production mode.even though i have returned true in gates.and removed authorize::class from middleware

    Reply
    • It looks like the gate() is a :void method, it doesn’t have a return.
      Try something like this instead.
      protected function gate()
      {
      Gate::define('viewTelescope', function ($user) {
      return in_array($user->email, [
      'taylor@laravel.com',
      ]);
      });
      }

      Reply

Leave a Comment