TelescopeServiceProvider.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 in_array($user->email, [
  57. //
  58. ]);
  59. });
  60. }
  61. }