PaymentSplitService.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. ->with(['payment.schedule.client.user', 'provider.user', 'providerWithdrawal'])
  11. ->orderBy('created_at', 'desc')
  12. ->get();
  13. }
  14. public function findById(int $id): ?PaymentSplit
  15. {
  16. return PaymentSplit::query()
  17. ->with(['payment.schedule.client.user', 'provider.user', 'providerWithdrawal'])
  18. ->find($id);
  19. }
  20. public function create(array $data): PaymentSplit
  21. {
  22. return PaymentSplit::create($data);
  23. }
  24. public function update(int $id, array $data): ?PaymentSplit
  25. {
  26. $model = $this->findById($id);
  27. if (! $model) {
  28. return null;
  29. }
  30. $model->update($data);
  31. return $model->fresh();
  32. }
  33. public function delete(int $id): bool
  34. {
  35. $model = $this->findById($id);
  36. if (! $model) {
  37. return false;
  38. }
  39. return $model->delete();
  40. }
  41. }