This commit is contained in:
EwelinaLasowy
2022-04-13 11:40:44 +02:00
parent 4af0482a93
commit 2f27c83411
9 changed files with 310 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers;
use Illuminate\Http\Request;
use Inertia\Response;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\Key;
use Toby\Infrastructure\Http\Resources\KeyResource;
class KeysController extends Controller
{
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
{
$keys = Key::query()->get();
return inertia("Keys/Index", [
"keys" => KeyResource::collection($keys),
]);
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class KeyResource extends JsonResource
{
public static $wrap = null;
public function toArray($request): array
{
return [
"id" => $this->id,
"owner" => new UserResource($this->owner),
"previousOwner" => new UserResource($this->previousOwner),
"updatedAt" => $this->updated_at->toDatetimeString(),
];
}
}