Нет описания

AuthServiceProvider.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Providers;
  3. use App\Course;
  4. use App\Policies\CoursePolicy;
  5. use Illuminate\Support\Facades\Gate;
  6. use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
  7. class AuthServiceProvider extends ServiceProvider
  8. {
  9. /**
  10. * The policy mappings for the application.
  11. *
  12. * @var array
  13. */
  14. protected $policies = [
  15. // 'App\Model' => 'App\Policies\ModelPolicy',
  16. Course::class => CoursePolicy::class,
  17. ];
  18. /**
  19. * Register any authentication / authorization services.
  20. *
  21. * @return void
  22. */
  23. public function boot()
  24. {
  25. $this->registerPolicies();
  26. Gate::define('add-permission', function ($user, $level, $division_id) {
  27. $user->loadMissing(['departments', 'faculties.departments']);
  28. return $user->is_admin
  29. || ($level === 1) &&
  30. ($user->departments->contains($division_id)
  31. || $user->faculties->contains(function ($faculty, $key) use ($division_id) {
  32. return $faculty->departments->contains($division_id);
  33. }))
  34. || ($level === 2 && $user->faculties->contains($division_id));
  35. });
  36. // Gate::define('')
  37. }
  38. }