-
app/Http/Resources/StarterKitResource.php
Open in GitHubuse Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class StarterKitResource extends JsonResource { public function toArray(Request $request): array { return [ 'id' => $this->id, 'title' => $this->title, 'slug' => $this->slug, 'installsCount' => $this->installs_count, 'user' => $this->whenLoaded('user', fn () => new UserResource($this->user), ), 'repoOrganisation' => $this->repo_organisation, 'repoName' => $this->repo_name, 'repoBranch' => $this->repo_branch, 'repoUrl' => $this->repo_branch === 'main' ? "https://github.com/{$this->repo_organisation}/{$this->repo_name}" : "https://github.com/{$this->repo_organisation}/{$this->repo_name}/tree/{$this->repo_branch}", 'isPublic' => $this->is_public, 'composerDependencies' => $this->composer_dependencies, 'nodeDependencies' => $this->node_dependencies, 'tags' => $this->getTags(), 'lastUpdatedAt' => $this->updated_at ?? $this->created_at, ]; } }
-
app/Http/Resources/UserResource.php
Open in GitHub<?php declare(strict_types=1); namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class UserResource extends JsonResource { public function toArray(Request $request): array { return [ 'id' => $this->id, 'name' => $this->name, 'image' => $this->image, 'createdAt' => $this->created_at, ]; } }
-
app/Http/Controllers/Kits/Show/PageController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Resources\StarterKitResource; use App\Models\StarterKit; use Illuminate\Http\Request; use Inertia\Inertia; class PageController extends Controller { public function __invoke(StarterKit $kit, Request $request) { if (!$request->user() && !$kit->is_public) { abort(404); } if ($request->user()?->cannot('see', $kit)) { abort(404); } $kit->load('user'); // ... return Inertia::render('Kits/Show/Page', [ 'kit' => new StarterKitResource($kit), ]); } }