Merge pull request #8560 from beganovich/projects-client-relationship

Client and tasks includes for project
This commit is contained in:
David Bomba 2023-06-16 09:51:48 +10:00 committed by GitHub
commit dace4a4370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Invoice Ninja (https://invoiceninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
@ -11,8 +12,10 @@
namespace App\Transformers; namespace App\Transformers;
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;
/** /**
@ -30,6 +33,8 @@ class ProjectTransformer extends EntityTransformer
* @var array * @var array
*/ */
protected $availableIncludes = [ protected $availableIncludes = [
'client',
'tasks',
]; ];
public function includeDocuments(Project $project) public function includeDocuments(Project $project)
@ -39,6 +44,20 @@ class ProjectTransformer extends EntityTransformer
return $this->includeCollection($project->documents, $transformer, Document::class); return $this->includeCollection($project->documents, $transformer, Document::class);
} }
public function includeClient(Project $project): \League\Fractal\Resource\Item
{
$transformer = new ClientTransformer($this->serializer);
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 [