TelescopeServiceProvider.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. public function register(): void
  13. {
  14. // Telescope::night();
  15. $this->hideSensitiveRequestDetails();
  16. $isLocal = $this->app->environment('local');
  17. Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
  18. return $isLocal ||
  19. $entry->isReportableException() ||
  20. $entry->isFailedRequest() ||
  21. $entry->isFailedJob() ||
  22. $entry->isScheduledTask() ||
  23. $entry->hasMonitoredTag();
  24. });
  25. }
  26. /**
  27. * Prevent sensitive request details from being logged by Telescope.
  28. */
  29. protected function hideSensitiveRequestDetails(): void
  30. {
  31. if ($this->app->environment('local')) {
  32. return;
  33. }
  34. Telescope::hideRequestParameters(['_token']);
  35. Telescope::hideRequestHeaders([
  36. 'cookie',
  37. 'x-csrf-token',
  38. 'x-xsrf-token',
  39. ]);
  40. }
  41. /**
  42. * Register the Telescope gate.
  43. *
  44. * This gate determines who can access Telescope in non-local environments.
  45. */
  46. protected function gate(): void
  47. {
  48. Gate::define('viewTelescope', function ($user) {
  49. return in_array($user->email, [
  50. "peterguo@lpchku.com"
  51. ]);
  52. });
  53. }
  54. }