EscolaLMS/Courses

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

Summary

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

namespace EscolaLms\Courses\Http\Resources;

use EscolaLms\ModelFields\Enum\MetaFieldVisibilityEnum;
use EscolaLms\ModelFields\Facades\ModelFields;
use Illuminate\Http\Resources\Json\JsonResource;

class TutorResource extends JsonResource
{
    public function toArray($request)
    {
        $fields = [
            'id' => $this->resource->id,
            'first_name' => $this->resource->first_name,
            'last_name' => $this->resource->last_name,
            'email' => $this->resource->email,
            'path_avatar' => $this->resource->path_avatar,
            'url_avatar' => $this->resource->avatar_url,
            'interests' => TutorInterestResource::collection($this->resource->interests),
        ];

        return array_merge(
            $fields,
            ['categories' => $this->resource->categories],
            ModelFields::getExtraAttributesValues($this->resource, MetaFieldVisibilityEnum::PUBLIC)
        );
    }
}