TelescopeServiceProvider.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * @return void
  33. */
  34. protected function hideSensitiveRequestDetails()
  35. {
  36. if ($this->app->environment('local')) {
  37. return;
  38. }
  39. Telescope::hideRequestParameters(['_token']);
  40. Telescope::hideRequestHeaders([
  41. 'cookie',
  42. 'x-csrf-token',
  43. 'x-xsrf-token',
  44. ]);
  45. }
  46. /**
  47. * Register the Telescope gate.
  48. *
  49. * This gate determines who can access Telescope in non-local environments.
  50. *
  51. * @return void
  52. */
  53. protected function gate()
  54. {
  55. Gate::define('viewTelescope', function ($user) {
  56. return $user->hasRole('Super Admin');
  57. });
  58. }
  59. }