-
app/Providers/AuthServiceProvider.php
Open in GitHubuse App\Models\Course; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Gate; class AuthServiceProvider extends ServiceProvider { // public function boot() { $this->registerPolicies(); Gate::define('edit-course-grades', function ($user, $course) { return $user->isTeacher() && $user->teacher_id == $course->teacher_id || $user->can('evaluation.edit'); }); // } }
-
app/Http/Controllers/GradeController.php
Open in GitHubuse App\Models\Course; use Illuminate\Support\Facades\Gate; class GradeController extends Controller { public function edit(Course $course) { $this->checkAccessForCourse($course); return view('grades.edit', [ 'enrollments' => $course->enrollments, 'course_grade_types' => $course->grade_types->sortBy('id'), 'grades' => $course->grades, 'course' => $course, ]); } // protected function checkAccessForCourse(Course $course): void { if (Gate::forUser(backpack_user())->denies('edit-course-grades', $course)) { abort(403); } } } }