TelescopeServiceProvider.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\Facades\Gate;
  4. use Laravel\Telescope\IncomingEntry;
  5. use Laravel\Telescope\Telescope;
  6. use Laravel\Telescope\TelescopeApplicationServiceProvider;
  7. class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
  8. {
  9. /**
  10. * Register any application services.
  11. *
  12. * @return void
  13. */
  14. public function register()
  15. {
  16. // Telescope::night();
  17. $this->hideSensitiveRequestDetails();
  18. Telescope::filter(function (IncomingEntry $entry) {
  19. if ($this->app->environment('local')) {
  20. return true;
  21. }
  22. return $entry->isReportableException() ||
  23. $entry->isFailedRequest() ||
  24. $entry->isFailedJob() ||
  25. $entry->isScheduledTask() ||
  26. $entry->hasMonitoredTag();
  27. });
  28. }
  29. /**
  30. * Prevent sensitive request details from being logged by Telescope.
  31. */
  32. protected function hideSensitiveRequestDetails(): void
  33. {
  34. if ($this->app->environment('local')) {
  35. return;
  36. }
  37. Telescope::hideRequestParameters(['_token']);
  38. Telescope::hideRequestHeaders([
  39. 'cookie',
  40. 'x-csrf-token',
  41. 'x-xsrf-token',
  42. ]);
  43. }
  44. /**
  45. * Register the Telescope gate.
  46. *
  47. * This gate determines who can access Telescope in non-local environments.
  48. *
  49. * @return void
  50. */
  51. protected function gate()
  52. {
  53. Gate::define('viewTelescope', function ($user) {
  54. return $user->hasRole('Super Admin');
  55. });
  56. }
  57. }