adrema/app/Invoice/Actions/PaymentPositionIndexAction.php

32 lines
807 B
PHP
Raw Normal View History

2023-12-17 21:13:52 +01:00
<?php
namespace App\Invoice\Actions;
use App\Invoice\Models\InvoicePosition;
use App\Invoice\Resources\InvoicePositionResource;
use App\Member\Member;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\Concerns\AsAction;
class PaymentPositionIndexAction
{
use AsAction;
/**
* @return Collection<int, InvoicePosition>
*/
public function handle(Member $member): Collection
{
return $member->load('invoicePositions.invoice')->invoicePositions;
}
public function asController(Member $member): JsonResponse
{
return response()->json([
'data' => InvoicePositionResource::collection($this->handle($member)),
]);
}
}