暫無描述

CoursePolicy.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Policies;
  3. use App\User;
  4. use App\Course;
  5. use Illuminate\Auth\Access\HandlesAuthorization;
  6. class CoursePolicy
  7. {
  8. use HandlesAuthorization;
  9. /**
  10. * Determine whether the user can view any courses.
  11. *
  12. * @param \App\User $user
  13. * @return mixed
  14. */
  15. public function viewAny(User $user)
  16. {
  17. return true;
  18. }
  19. /**
  20. * Determine whether the user can update the course.
  21. *
  22. * @param \App\User $user
  23. * @param \App\Course $course
  24. * @return mixed
  25. */
  26. public function update(User $user, Course $course)
  27. {
  28. return $user->departments->where('id', '=', $course->dept_id)->isNotEmpty()
  29. || $user->faculties->where('id', '=', $course->faculty->id)->isNotEmpty();
  30. }
  31. /**
  32. * Determine whether the user can delete the course.
  33. *
  34. * @param \App\User $user
  35. * @param \App\Course $course
  36. * @return mixed
  37. */
  38. public function delete(User $user, Course $course)
  39. {
  40. return $user->departments->where('id', '=', $course->dept_id)->isNotEmpty()
  41. || $user->faculties->where('id', '=', $course->faculty->id)->isNotEmpty();
  42. }
  43. }