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>
53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\PublicApi;
|
|
|
|
use App\Models\Testimonial;
|
|
use App\Support\ImagePayload;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @mixin Testimonial
|
|
*/
|
|
class PublicTestimonialResource extends JsonResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$locale = app()->getLocale();
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'quote' => $this->getTranslation('quote', $locale),
|
|
|
|
/*
|
|
* Whether these are the words that were actually said. A quote
|
|
* shown in a language it was not given in has been translated by
|
|
* us, and the frontend can say so — "translated from Spanish" —
|
|
* instead of pretending somebody phrased it that way.
|
|
*/
|
|
'original_locale' => $this->original_locale,
|
|
'is_original' => $this->isOriginal($locale),
|
|
|
|
'author' => [
|
|
'name' => $this->author_name,
|
|
'role' => $this->getTranslation('author_role', $locale, false) ?: null,
|
|
'avatar' => ImagePayload::make(
|
|
$this->avatar,
|
|
$this->resource->relationLoaded('avatarMedia') ? $this->resource->getRelation('avatarMedia') : null,
|
|
$this->author_name,
|
|
),
|
|
],
|
|
|
|
'given_at' => $this->given_at?->toDateString(),
|
|
|
|
'client' => PublicClientResource::make($this->whenLoaded('client')),
|
|
];
|
|
}
|
|
}
|