2021-09-22 22:50:45 +02:00
|
|
|
<?php
|
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
namespace App\Api\v1\Resources;
|
2021-09-22 22:50:45 +02:00
|
|
|
|
|
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
|
|
|
|
|
|
class TwoFAccountCollection extends ResourceCollection
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The resource that this resource collects.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2022-11-21 11:16:43 +01:00
|
|
|
public $collects = TwoFAccountReadResource::class;
|
2021-09-22 22:50:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the resource collection into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2022-11-21 11:16:43 +01:00
|
|
|
* @return \Illuminate\Support\Collection<int|string, TwoFAccountReadResource>
|
2021-09-22 22:50:45 +02:00
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
// By default we want this collection to not return the secret.
|
|
|
|
// The underlying TwoFAccountReadResource hides the secret only when withSecret == false.
|
|
|
|
// When withSecret is provided the underlying resource will return secret according to the parameter value
|
|
|
|
// If no withSecret is set we force it to false to ensure the secret will not being returned.
|
2022-11-22 15:15:52 +01:00
|
|
|
if (! $request->has('withSecret')) {
|
2021-09-22 22:50:45 +02:00
|
|
|
$request->merge(['withSecret' => false]);
|
|
|
|
}
|
|
|
|
|
2023-04-14 17:13:28 +02:00
|
|
|
if ($request->has('withOtp')) {
|
|
|
|
$request->merge(['at' => time()]);
|
|
|
|
}
|
|
|
|
|
2021-09-22 22:50:45 +02:00
|
|
|
return $this->collection;
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|