Add tasks to transformer

This commit is contained in:
Benjamin Beganović 2023-06-15 14:43:51 +02:00
parent 781ecb34fc
commit 04300c830f

View File

@ -15,6 +15,7 @@ namespace App\Transformers;
use App\Models\Client; use App\Models\Client;
use App\Models\Document; use App\Models\Document;
use App\Models\Project; use App\Models\Project;
use App\Models\Task;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
/** /**
@ -33,6 +34,7 @@ class ProjectTransformer extends EntityTransformer
*/ */
protected $availableIncludes = [ protected $availableIncludes = [
'client', 'client',
'tasks',
]; ];
public function includeDocuments(Project $project) public function includeDocuments(Project $project)
@ -49,6 +51,13 @@ class ProjectTransformer extends EntityTransformer
return $this->includeItem($project->client, $transformer, Client::class); return $this->includeItem($project->client, $transformer, Client::class);
} }
public function includeTasks(Project $project): \League\Fractal\Resource\Collection
{
$transformer = new TaskTransformer($this->serializer);
return $this->includeCollection($project->tasks, $transformer, Task::class);
}
public function transform(Project $project) public function transform(Project $project)
{ {
return [ return [