HorizonServiceProvider.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\Facades\Gate;
  4. use Laravel\Horizon\Horizon;
  5. use Laravel\Horizon\HorizonApplicationServiceProvider;
  6. class HorizonServiceProvider extends HorizonApplicationServiceProvider
  7. {
  8. /**
  9. * Bootstrap any application services.
  10. */
  11. public function boot(): void
  12. {
  13. parent::boot();
  14. // Horizon::routeSmsNotificationsTo('15556667777');
  15. // Horizon::routeMailNotificationsTo('example@example.com');
  16. // Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel');
  17. }
  18. /**
  19. * Authorize Horizon with the admin guard.
  20. *
  21. * The default guard is customer, so the framework callback would inspect
  22. * the storefront user. Dashboard access follows the admin session instead.
  23. */
  24. protected function authorization(): void
  25. {
  26. $this->gate();
  27. Horizon::auth(function ($request) {
  28. return Gate::forUser($request->user('admin'))->check('viewHorizon')
  29. || app()->environment('local');
  30. });
  31. }
  32. /**
  33. * Register the Horizon gate.
  34. *
  35. * This gate determines who can access Horizon in non-local environments.
  36. */
  37. protected function gate(): void
  38. {
  39. Gate::define('viewHorizon', function ($user = null) {
  40. return in_array(optional($user)->email, [
  41. 'admin@longyi.com',
  42. ]);
  43. });
  44. }
  45. }