TelescopeServiceProvider.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Providers;
  3. use App\Models\AppSession;
  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 true;
  24. return $entry->isReportableException() ||
  25. $entry->isFailedRequest() ||
  26. $entry->isFailedJob() ||
  27. $entry->isScheduledTask() ||
  28. $entry->hasMonitoredTag();
  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. 'cookie',
  44. 'x-csrf-token',
  45. 'x-xsrf-token',
  46. ]);
  47. }
  48. /**
  49. * Register the Telescope gate.
  50. *
  51. * This gate determines who can access Telescope in non-local environments.
  52. *
  53. * @return void
  54. */
  55. // protected function gate()
  56. // {
  57. // Gate::define('viewTelescope', function ($user) {
  58. // $sessionKey = request()->cookie('sessionKey');
  59. // $appSession = AppSession::where('session_key', $sessionKey)->where('is_active', true)->first();
  60. // $authenticated = $sessionKey && $appSession && $appSession->pro && $appSession->pro->pro_type == 'ADMIN';
  61. // if (!$authenticated) {
  62. // //return redirect('/');
  63. // return abort(403);
  64. // }
  65. // return false;
  66. //
  67. //
  68. // });
  69. // }
  70. //
  71. protected function authorization()
  72. {
  73. $this->gate();
  74. Telescope::auth(function ($request) {
  75. $sessionKey = request()->cookie('sessionKey');
  76. $appSession = AppSession::where('session_key', $sessionKey)->where('is_active', true)->first();
  77. $authenticated = $sessionKey && $appSession && $appSession->pro && $appSession->pro->pro_type == 'ADMIN';
  78. if (!$authenticated) {
  79. return abort(403);
  80. }
  81. return true;
  82. });
  83. }
  84. }