PaymentSplitService.php 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Services;
  3. use App\Models\PaymentSplit;
  4. use Illuminate\Database\Eloquent\Collection;
  5. class PaymentSplitService
  6. {
  7. public function getAll(): Collection
  8. {
  9. return PaymentSplit::query()
  10. ->orderBy('created_at', 'desc')
  11. ->get();
  12. }
  13. public function findById(int $id): ?PaymentSplit
  14. {
  15. return PaymentSplit::find($id);
  16. }
  17. public function create(array $data): PaymentSplit
  18. {
  19. return PaymentSplit::create($data);
  20. }
  21. public function update(int $id, array $data): ?PaymentSplit
  22. {
  23. $model = $this->findById($id);
  24. if (! $model) {
  25. return null;
  26. }
  27. $model->update($data);
  28. return $model->fresh();
  29. }
  30. public function delete(int $id): bool
  31. {
  32. $model = $this->findById($id);
  33. if (! $model) {
  34. return false;
  35. }
  36. return $model->delete();
  37. }
  38. }