adrema/app/Membership/Actions/IndexAction.php

32 lines
757 B
PHP
Raw Normal View History

2023-09-12 16:54:13 +02:00
<?php
namespace App\Membership\Actions;
use App\Member\Member;
use App\Member\Membership;
use App\Membership\MembershipResource;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\Concerns\AsAction;
2023-10-16 12:52:59 +02:00
class IndexAction
2023-09-12 16:54:13 +02:00
{
use AsAction;
/**
* @return Collection<int, Membership>
*/
public function handle(Member $member): Collection
{
return $member->memberships;
}
public function asController(Member $member): AnonymousResourceCollection
{
return MembershipResource::collection($this->handle($member))
->additional([
'meta' => MembershipResource::memberMeta($member)
]);
}
}