adrema/app/Course/Actions/CourseIndexAction.php

32 lines
804 B
PHP
Raw Permalink Normal View History

2023-10-18 01:11:36 +02:00
<?php
namespace App\Course\Actions;
2023-10-18 18:14:07 +02:00
use App\Course\Models\CourseMember;
2023-10-18 01:11:36 +02:00
use App\Course\Resources\CourseMemberResource;
use App\Member\Member;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\Concerns\AsAction;
class CourseIndexAction
{
use AsAction;
/**
2023-10-18 18:14:07 +02:00
* @return Collection<int, CourseMember>
2023-10-18 01:11:36 +02:00
*/
public function handle(Member $member): Collection
{
return $member->courses()->with('course')->get();
}
public function asController(Member $member): AnonymousResourceCollection
{
return CourseMemberResource::collection($this->handle($member))
->additional([
'meta' => CourseMemberResource::memberMeta($member),
]);
}
}