Skip to content

Commit

Permalink
Implemented more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Sep 4, 2024
1 parent cf5929e commit 2e3124f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/Services/Entity/RecoverySetupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function search(): array

protected function elements(): array
{
//Query yields array of objects
$elements = DB::select(
'select id, name, deleted_at, deleted_by, type_id, "entity" as type
from entities
Expand All @@ -73,13 +74,16 @@ protected function elements(): array
' order by deleted_at DESC'
);

//We fill the rest of the data needed into the objects
$users = $this->campaign->users()->pluck('users.name', 'users.id')->toArray();
foreach ($elements as $key => $element) {
$element->deleted_name = $users[$element->deleted_by] ?? 'Unknown';
$element->date = \Carbon\Carbon::createFromTimeStamp(strtotime($element->deleted_at))->diffForHumans();
$element->position = $key;
}
//This will cast each object in the array to an array, and the toArray gets you from the collection back to an array.

//We want to send an array of arrays to JS.
//So this will cast each object in the array to an array, and the toArray gets you from the collection back to an array.
return collect($elements)->map(function ($x) { return (array) $x; })->toArray();
}

Expand Down

0 comments on commit 2e3124f

Please sign in to comment.