AuthServiceProvider.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
  4. use Illuminate\Support\Carbon;
  5. use Illuminate\Support\Facades\Gate;
  6. use Illuminate\Support\Facades\Route;
  7. use Laravel\Passport\Passport;
  8. class AuthServiceProvider extends ServiceProvider
  9. {
  10. /**
  11. * The policy mappings for the application.
  12. *
  13. * @var array
  14. */
  15. protected $policies = [
  16. 'App\Model' => 'App\Policies\ModelPolicy',
  17. ];
  18. /**
  19. * Register any authentication / authorization services.
  20. *
  21. * @return void
  22. */
  23. public function boot()
  24. {
  25. $this->registerPolicies();
  26. // Implicitly grant "Admin" role all permissions
  27. // This works in the app by using gate-related functions like auth()->user->can() and @can()
  28. Gate::before(function ($user, $ability) {
  29. return $user->hasRole('superAdmin') ? true : null;
  30. });
  31. Passport::routes();
  32. Passport::$ignoreCsrfToken = true;
  33. Passport::tokensExpireIn(Carbon::now()->addDays(15));
  34. Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));
  35. }
  36. }