Thanks for your feedback!
I made like :
<?php
namespace App\Http\Resources;
use App\Facades\MyFuncsClass;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TaskCollection extends ResourceCollection
{
public function toArray($task)
{
return [
$this->collection->transform(function($task){
return [
'id' => $task->id,
'name' => $task->name,
'slug' => $task->slug,
'price' => $task->price,
'description' => $task->description,
'creator_id' => $task->creator_id,
'leader_id' => $task->leader_id,
'category_id' => $task->category_id,
'priority' => $task->priority,
'status' => $task->status,
'date_start' => $task->date_start,
'date_start_formatted' => MyFuncsClass::mySqlToStringDate($task->date_start),
'date_end' => $task->date_end,
'date_end_formatted' => MyFuncsClass::mySqlToStringDate($task->date_end),
'needs_reports' => $task->needs_reports,
'image' => $task->image,
'leader_name' => $task->leader_name,
'category_name' => $task->category_name,
'category_slug' => $task->category_slug,
'filenameData' => $task->filenameData,
'taskRequireSkills' => !empty($task->taskRequireSkills) ? $task->taskRequireSkills : [],
'events' => !empty($task->events) ? $task->events : [],
'events_count' => !empty($task->events_count) ? $task->events_count : 0,
'created_at' => $task->created_at,
'updated_at' => $task->updated_at,
];
}),
];
}
public function with($task)
{
return [
'meta' => [
'version'=>'1.0.2'
]
];
}
}
and the only question I have is how to pass 1 more parameter tasks_total_count, which I need for pagination of my page?
I can not put it in “with” method as it is changable value for any request.
I can set this value in any $task row, but this way seems not good...