ProviderPaymentMethodController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Requests\ProviderPaymentMethodRequest;
  4. use App\Http\Resources\ProviderPaymentMethodResource;
  5. use App\Services\ProviderPaymentMethodService;
  6. use Illuminate\Http\JsonResponse;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  9. class ProviderPaymentMethodController extends Controller
  10. {
  11. public function __construct(
  12. private readonly ProviderPaymentMethodService $service
  13. ) {}
  14. public function index($id): JsonResponse
  15. {
  16. // $providerId = $request->query('provider_id');
  17. $paymentMethods = $this->service->getByProvider($id);
  18. // return ProviderPaymentMethodResource::collection($paymentMethods);
  19. return $this->successResponse(
  20. payload: ProviderPaymentMethodResource::collection($paymentMethods)
  21. );
  22. }
  23. public function show(int $id): ProviderPaymentMethodResource
  24. {
  25. $paymentMethod = $this->service->findById($id);
  26. abort_if(!$paymentMethod, 404);
  27. return new ProviderPaymentMethodResource($paymentMethod);
  28. }
  29. public function store(ProviderPaymentMethodRequest $request): JsonResponse
  30. {
  31. $paymentMethod = $this->service->create($request->validated());
  32. return $this->successResponse(
  33. payload: new ProviderPaymentMethodResource($paymentMethod)
  34. );
  35. }
  36. public function update(ProviderPaymentMethodRequest $request, int $id): JsonResponse
  37. {
  38. $paymentMethod = $this->service->findById($id);
  39. abort_if(!$paymentMethod, 404);
  40. $paymentMethod = $this->service->update($paymentMethod, $request->validated());
  41. return $this->successResponse(
  42. payload: new ProviderPaymentMethodResource($paymentMethod)
  43. );
  44. }
  45. public function destroy(int $id): JsonResponse
  46. {
  47. $paymentMethod = $this->service->findById($id);
  48. abort_if(!$paymentMethod, 404);
  49. $this->service->delete($paymentMethod);
  50. return $this->successResponse(
  51. message: __("messages.deleted"),
  52. code: 204,
  53. );
  54. }
  55. }