Hello,
I am working on a project manager app. In that app, I want to display the 'pending' tasks according to due date.
i.e. task having closest due date on top.
Now, if there are many task for a given date, then I want to sort them according to priority. i.e. High priority on top.
But, I don't want to have collection keys as 'date'. I just want to have normal collection sorted out. See my code and please suggest.
Is it possible?
$this->authorize('view', $project);
$pendingTasks = $project->tasks->filter(function ($task) {
return !$task->completed_at;
});
$pendingTasks = $pendingTasks->sortBy('due_date');
// $pendingTasks = $pendingTasks->groupBy(['due_date', function($item) {
// return $item['priority'];
// }], $preserveKeys = true);
// dd($pendingTasks->toArray());
$completedTasks = $project->tasks->filter(function ($task) {
return $task->completed_at;
});
$completedTasks = $completedTasks->sortByDesc('completed_at');
return view('project.show', [
'project' => $project,
'pendingTasks' => $pendingTasks,
'completeTasks' => $completedTasks
]);