Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

EstimatePolicy.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Policies;
  3. use App\Enums\Accounting\EstimateStatus;
  4. use App\Models\Accounting\Estimate;
  5. use App\Models\User;
  6. class EstimatePolicy
  7. {
  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, Estimate $estimate): bool
  19. {
  20. return $user->belongsToCompany($estimate->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, Estimate $estimate): bool
  33. {
  34. if ($estimate->status === EstimateStatus::Converted) {
  35. return false;
  36. }
  37. return $user->belongsToCompany($estimate->company);
  38. }
  39. /**
  40. * Determine whether the user can delete the model.
  41. */
  42. public function delete(User $user, Estimate $estimate): bool
  43. {
  44. return $user->belongsToCompany($estimate->company);
  45. }
  46. /**
  47. * Determine whether the user can restore the model.
  48. */
  49. public function restore(User $user, Estimate $estimate): bool
  50. {
  51. return $user->belongsToCompany($estimate->company);
  52. }
  53. /**
  54. * Determine whether the user can permanently delete the model.
  55. */
  56. public function forceDelete(User $user, Estimate $estimate): bool
  57. {
  58. return $user->belongsToCompany($estimate->company);
  59. }
  60. }