FinancialAccountPayableService.php 1.0 KB

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