Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created August 9, 2019 17:38
Show Gist options
  • Save whoisryosuke/c80c0b6a740e552b950f45e84de4e1d1 to your computer and use it in GitHub Desktop.
Save whoisryosuke/c80c0b6a740e552b950f45e84de4e1d1 to your computer and use it in GitHub Desktop.
Laravel / Telescope - Enable telescope for a staging or other environment - via: https://github.com/laravel/telescope/issues/76

If you've been following the instructions in the section "Installing Only In Specific Environments" you'll need to ensure that you update your AppServiceProvider accordingly, e.g.

    public function register()
    {
    	if ($this->app->environment('local') || $this->app->environment('staging')) {
    		$this->app->register(TelescopeServiceProvider::class);
    	}
    }

The problem appears to be the following method in TelescopeApplicationServiceProvider:

 /**
 * Configure the Telescope authorization services.
 *
 * @return void
 */
 protected function authorization()
 {
 $this->gate();

 Telescope::auth(function ($request) {
 return app()->environment('local') ||
 Gate::check('viewTelescope', [$request->user()]);
 });
 }

I overrode this method in my TelescopeServiceProvider and defined my own auth closure (add this function to app/Providers/TelescopeServiceProvider.php):

 /**
 * Configure the Telescope authorization services.
 *
 * @return void
 */
 protected function authorization()
 {
 $this->gate();

 Telescope::auth(function ($request) {
 return app()->environment(['local', 'staging']) ||
 Gate::check('viewTelescope', [$request->user()]);
 });
 }

This allowed me to access telescope in my staging environment. I tried changing my gate() override and it didn't appear to work. This was the only way that I could reliably get it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment