Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
62
app/Http/Resources/PublicApi/PublicServiceResource.php
Normal file
62
app/Http/Resources/PublicApi/PublicServiceResource.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Service;
|
||||
use App\Support\SiteUrls;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Service
|
||||
*/
|
||||
class PublicServiceResource extends JsonResource
|
||||
{
|
||||
protected bool $detailed = false;
|
||||
|
||||
public function detailed(bool $detailed = true): static
|
||||
{
|
||||
$this->detailed = $detailed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'locale' => $locale,
|
||||
|
||||
...TranslatablePayload::resolve($this->resource, ['title', 'slug', 'tagline'], $locale),
|
||||
|
||||
'icon' => $this->icon,
|
||||
'is_featured' => $this->is_featured,
|
||||
'position' => $this->position,
|
||||
'updated_at' => $this->updated_at?->toIso8601String(),
|
||||
|
||||
$this->mergeWhen($this->detailed, fn () => TranslatablePayload::resolve(
|
||||
$this->resource,
|
||||
['description', 'meta_title', 'meta_description'],
|
||||
$locale,
|
||||
)),
|
||||
|
||||
// The work that backs the offer. Without it a service is a
|
||||
// promise, which is why it travels with it rather than being
|
||||
// something the frontend has to go and ask for.
|
||||
'projects' => PublicProjectResource::collection($this->whenLoaded('projects')),
|
||||
'technologies' => PublicTechnologyResource::collection($this->whenLoaded('technologies')),
|
||||
'testimonials' => PublicTestimonialResource::collection($this->whenLoaded('testimonials')),
|
||||
|
||||
'alternates' => SiteUrls::alternates($this->resource, 'service'),
|
||||
'path' => SiteUrls::alternates($this->resource, 'service')[$locale] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user