Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

laravelstart/laravelstart

20 stars
3 code files
View laravelstart/laravelstart on GitHub

app/Http/Resources/StarterKitResource.php

Open in GitHub
use 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 GitHub
use 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),
]);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.