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>
107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\BumpsContentVersion;
|
|
use App\Models\Concerns\HasImages;
|
|
use App\Models\Concerns\HasRevisions;
|
|
use Database\Factories\TestimonialFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Translatable\HasTranslations;
|
|
|
|
/**
|
|
* What somebody else says about the work.
|
|
*
|
|
* Attached to a client, a project or a service rather than to "the home page":
|
|
* the frontend asks for the ones belonging to whatever it is rendering, which
|
|
* is what stops this becoming a page-builder block.
|
|
*/
|
|
#[Fillable([
|
|
'quote', 'original_locale', 'author_name', 'author_role', 'avatar',
|
|
'client_id', 'project_id', 'service_id', 'is_public', 'position', 'given_at',
|
|
])]
|
|
class Testimonial extends Model
|
|
{
|
|
/** @use HasFactory<TestimonialFactory> */
|
|
use BumpsContentVersion, HasFactory, HasImages, HasRevisions, HasTranslations, SoftDeletes;
|
|
|
|
/** @var array<int, string> */
|
|
public array $translatable = ['quote', 'author_role'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_public' => 'boolean',
|
|
'position' => 'integer',
|
|
'given_at' => 'date',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public function imageAttributes(): array
|
|
{
|
|
return ['avatar'];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Media, $this>
|
|
*/
|
|
public function avatarMedia(): BelongsTo
|
|
{
|
|
return $this->imageRelation('avatar');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Client, $this>
|
|
*/
|
|
public function client(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Client::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Project, $this>
|
|
*/
|
|
public function project(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Service, $this>
|
|
*/
|
|
public function service(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Service::class);
|
|
}
|
|
|
|
/**
|
|
* Whether the text being shown is the one that was actually said.
|
|
*
|
|
* A translated quote is words put in somebody's mouth, so the frontend is
|
|
* told, and can say "translated from Spanish" instead of pretending.
|
|
*/
|
|
public function isOriginal(?string $locale = null): bool
|
|
{
|
|
return ($locale ?? app()->getLocale()) === $this->original_locale;
|
|
}
|
|
|
|
/**
|
|
* @param Builder<$this> $query
|
|
* @return Builder<$this>
|
|
*/
|
|
public function scopePublic(Builder $query): Builder
|
|
{
|
|
return $query->where('is_public', true);
|
|
}
|
|
}
|