2021-06-18 15:39:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
|
|
|
|
|
|
|
|
class UserLabeledResource extends ResourceCollection
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Transform the resource collection into an array.
|
|
|
|
|
*
|
2022-08-30 13:21:07 +00:00
|
|
|
* @param mixed $request
|
2021-06-18 15:39:19 +02:00
|
|
|
* @return array
|
2022-08-30 13:21:07 +00:00
|
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
2021-06-18 15:39:19 +02:00
|
|
|
*/
|
|
|
|
|
public function toArray($request)
|
|
|
|
|
{
|
2022-08-30 13:21:07 +00:00
|
|
|
// phpcs:enable
|
2021-06-18 15:39:19 +02:00
|
|
|
return $this->collection->mapWithKeys(function (User $user, $key) {
|
|
|
|
|
return [
|
|
|
|
|
$key => [
|
|
|
|
|
'label' => sprintf('%d %s', $user->id, $user->name),
|
|
|
|
|
'key' => $user->id
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|