| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?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);
- abort_if(!$paymentMethod, 404);
- 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);
- abort_if(!$paymentMethod, 404);
-
- $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,
- );
- }
- }
|