TelescopeServiceProvider.php 1.8 KB

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