You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompanyPolicy.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Policies;
  3. use App\Models\Company;
  4. use App\Models\User;
  5. use Illuminate\Auth\Access\HandlesAuthorization;
  6. class CompanyPolicy
  7. {
  8. use HandlesAuthorization;
  9. /**
  10. * Determine whether the user can view any models.
  11. */
  12. public function viewAny(User $user): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * Determine whether the user can view the model.
  18. */
  19. public function view(User $user, Company $company): bool
  20. {
  21. return $user->belongsToCompany($company);
  22. }
  23. /**
  24. * Determine whether the user can create models.
  25. */
  26. public function create(User $user): bool
  27. {
  28. if (is_demo_environment()) {
  29. return false;
  30. }
  31. return true;
  32. }
  33. /**
  34. * Determine whether the user can update the model.
  35. */
  36. public function update(User $user, Company $company): bool
  37. {
  38. if (is_demo_environment()) {
  39. return false;
  40. }
  41. return $user->ownsCompany($company);
  42. }
  43. /**
  44. * Determine whether the user can add company employees.
  45. */
  46. public function addCompanyEmployee(User $user, Company $company): bool
  47. {
  48. if (is_demo_environment()) {
  49. return false;
  50. }
  51. return $user->ownsCompany($company);
  52. }
  53. /**
  54. * Determine whether the user can update company employee permissions.
  55. */
  56. public function updateCompanyEmployee(User $user, Company $company): bool
  57. {
  58. if (is_demo_environment()) {
  59. return false;
  60. }
  61. return $user->ownsCompany($company);
  62. }
  63. /**
  64. * Determine whether the user can remove company employees.
  65. */
  66. public function removeCompanyEmployee(User $user, Company $company): bool
  67. {
  68. if (is_demo_environment()) {
  69. return false;
  70. }
  71. return $user->ownsCompany($company);
  72. }
  73. /**
  74. * Determine whether the user can delete the model.
  75. */
  76. public function delete(User $user, Company $company): bool
  77. {
  78. if (is_demo_environment()) {
  79. return false;
  80. }
  81. return $user->ownsCompany($company);
  82. }
  83. }