TelescopeServiceProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Providers;
  3. use Laravel\Telescope\Telescope;
  4. use Illuminate\Support\Facades\Gate;
  5. use Laravel\Telescope\IncomingEntry;
  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->isLocal()) {
  20. return true;
  21. }
  22. return $entry->isReportableException() ||
  23. $entry->isFailedJob() ||
  24. $entry->isScheduledTask() ||
  25. $entry->hasMonitoredTag();
  26. });
  27. }
  28. /**
  29. * Prevent sensitive request details from being logged by Telescope.
  30. *
  31. * @return void
  32. */
  33. protected function hideSensitiveRequestDetails()
  34. {
  35. if ($this->app->isLocal()) {
  36. return;
  37. }
  38. Telescope::hideRequestParameters(['_token']);
  39. Telescope::hideRequestHeaders([
  40. 'cookie',
  41. 'x-csrf-token',
  42. 'x-xsrf-token',
  43. ]);
  44. }
  45. /**
  46. * Register the Telescope gate.
  47. *
  48. * This gate determines who can access Telescope in non-local environments.
  49. *
  50. * @return void
  51. */
  52. protected function gate()
  53. {
  54. Gate::define('viewTelescope', function ($user) {
  55. return in_array($user->account, [
  56. //
  57. 'admin'
  58. ]);
  59. });
  60. }
  61. }