Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CompanyPolicy.php 1.7KB

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