| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Http\Controllers;
- use App\Http\Requests\ProviderPaymentMethodRequest;
- use App\Http\Resources\ProviderPaymentMethodResource;
- use App\Services\ProviderPaymentMethodService;
- use Illuminate\Http\JsonResponse;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
- class ProviderPaymentMethodController extends Controller
- {
- public function __construct(
- private readonly ProviderPaymentMethodService $service
- ) {}
- public function index($id): JsonResponse
- {
- $paymentMethods = $this->service->getByProvider($id);
- return $this->successResponse(
- payload: ProviderPaymentMethodResource::collection($paymentMethods)
- );
- }
- public function show(int $id): ProviderPaymentMethodResource
- {
- $paymentMethod = $this->service->findById($id);
- return new ProviderPaymentMethodResource($paymentMethod);
- }
- public function store(ProviderPaymentMethodRequest $request): JsonResponse
- {
- $paymentMethod = $this->service->create($request->validated());
- return $this->successResponse(
- payload: new ProviderPaymentMethodResource($paymentMethod)
- );
- }
- public function update(ProviderPaymentMethodRequest $request, int $id): JsonResponse
- {
- $paymentMethod = $this->service->findById($id);
-
- $paymentMethod = $this->service->update($paymentMethod, $request->validated());
- return $this->successResponse(
- payload: new ProviderPaymentMethodResource($paymentMethod)
- );
- }
- public function destroy(int $id): JsonResponse
- {
- $paymentMethod = $this->service->findById($id);
-
- $this->service->delete($paymentMethod);
- return $this->successResponse(
- message: __("messages.deleted"),
- code: 204,
- );
- }
- }
|