CustomFilterPolicy.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Policies;
  3. use App\Models\CustomFilter;
  4. use App\User;
  5. class CustomFilterPolicy
  6. {
  7. /**
  8. * Determine whether the user can view any models.
  9. */
  10. public function viewAny(User $user): bool
  11. {
  12. return false;
  13. }
  14. /**
  15. * Determine whether the user can view the custom filter.
  16. *
  17. * @param \App\User $user
  18. * @param \App\Models\CustomFilter $filter
  19. * @return bool
  20. */
  21. public function view(User $user, CustomFilter $filter)
  22. {
  23. return $user->profile_id === $filter->profile_id;
  24. }
  25. /**
  26. * Determine whether the user can create models.
  27. */
  28. public function create(User $user): bool
  29. {
  30. return CustomFilter::whereProfileId($user->profile_id)->count() <= 100;
  31. }
  32. /**
  33. * Determine whether the user can update the custom filter.
  34. *
  35. * @param \App\User $user
  36. * @param \App\Models\CustomFilter $filter
  37. * @return bool
  38. */
  39. public function update(User $user, CustomFilter $filter)
  40. {
  41. return $user->profile_id === $filter->profile_id;
  42. }
  43. /**
  44. * Determine whether the user can delete the custom filter.
  45. *
  46. * @param \App\User $user
  47. * @param \App\Models\CustomFilter $filter
  48. * @return bool
  49. */
  50. public function delete(User $user, CustomFilter $filter)
  51. {
  52. return $user->profile_id === $filter->profile_id;
  53. }
  54. }