TelescopeServiceProvider.php 1.6 KB

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