EscolaLMS/Courses-Import-Export

View on GitHub
src/Http/Resources/LessonExportResource.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace EscolaLms\CoursesImportExport\Http\Resources;

use EscolaLms\Courses\Models\Lesson;
use Illuminate\Http\Resources\Json\JsonResource;

class LessonExportResource extends JsonResource
{
    public function __construct(Lesson $resource)
    {
        parent::__construct($resource);
    }

    public function getResource(): Lesson
    {
        return $this->resource;
    }

    /**
     * @param \Illuminate\Http\Request $request
     */
    public function toArray($request): array
    {
        $lesson = $this->getResource();

        return [
            'title' => $lesson->title,
            'summary' => $lesson->summary,
            'duration' => $lesson->duration,
            'active' => $lesson->active,
            'topics' => TopicExportResource::collection($lesson->topics->sortBy('order')),
            'order' => $lesson->order,
            'lessons' => LessonExportResource::collection($lesson->lessons),
        ];
    }
}