1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
-
- namespace App\Providers;
-
- use App\Course;
- use App\Policies\CoursePolicy;
- use Illuminate\Support\Facades\Gate;
- use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
-
- class AuthServiceProvider extends ServiceProvider
- {
- /**
- * The policy mappings for the application.
- *
- * @var array
- */
- protected $policies = [
- // 'App\Model' => 'App\Policies\ModelPolicy',
- Course::class => CoursePolicy::class,
- ];
-
- /**
- * Register any authentication / authorization services.
- *
- * @return void
- */
- public function boot()
- {
- $this->registerPolicies();
-
- Gate::define('add-permission', function ($user, $level, $division_id) {
- $user->loadMissing(['departments', 'faculties.departments']);
- return $user->is_admin
- || ($level === 1) &&
- ($user->departments->contains($division_id)
- || $user->faculties->contains(function ($faculty, $key) use ($division_id) {
- return $faculty->departments->contains($division_id);
- }))
- || ($level === 2 && $user->faculties->contains($division_id));
- });
-
- // Gate::define('')
- }
- }
|