TelescopeServiceProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Providers;
  3. use App\Models\User;
  4. use Illuminate\Support\Facades\Gate;
  5. use Laravel\Telescope\IncomingEntry;
  6. use Laravel\Telescope\Telescope;
  7. use Laravel\Telescope\TelescopeApplicationServiceProvider;
  8. class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
  9. {
  10. /**
  11. * Register any application services.
  12. *
  13. * @return void
  14. */
  15. public function register()
  16. {
  17. // Telescope::night();
  18. $this->hideSensitiveRequestDetails();
  19. Telescope::filter(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. * Prevent sensitive request details from being logged by Telescope.
  32. */
  33. protected function hideSensitiveRequestDetails(): void
  34. {
  35. if ($this->app->environment('local')) {
  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 $user) {
  55. return $user->hasPermissionTo('telescope.index');
  56. });
  57. }
  58. }