PlanService.php 570 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Services;
  3. use App\Models\Plan;
  4. class PlanService
  5. {
  6. public $plan;
  7. public function __construct(int $planId)
  8. {
  9. $this->plan = Plan::lockForUpdate()->find($planId);
  10. }
  11. public function incrementInventory()
  12. {
  13. if ($this->plan->inventory_limit !== NULL) {
  14. return $this->plan->increment('inventory_limit');
  15. }
  16. }
  17. public function decrementInventory()
  18. {
  19. if ($this->plan->inventory_limit !== NULL) {
  20. return $this->plan->decrement('inventory_limit');
  21. }
  22. }
  23. }