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:
129
app/Models/Service.php
Normal file
129
app/Models/Service.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BumpsContentVersion;
|
||||
use App\Models\Concerns\HasContentViews;
|
||||
use App\Models\Concerns\HasPublicationWindow;
|
||||
use App\Models\Concerns\HasReviews;
|
||||
use App\Models\Concerns\HasRevisions;
|
||||
use App\Models\Concerns\RecordsSlugChanges;
|
||||
use Database\Factories\ServiceFactory;
|
||||
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\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
/**
|
||||
* Something the collective offers to do.
|
||||
*
|
||||
* The counterpart to a project: one says what has been built, this says what
|
||||
* you would be asking for. A portfolio without it is a list of work with no
|
||||
* explanation of what somebody is supposed to do about it.
|
||||
*
|
||||
* The relation to projects is what keeps it honest — a service that cannot
|
||||
* point at a real piece of work is a promise.
|
||||
*/
|
||||
#[Fillable([
|
||||
'title', 'slug', 'tagline', 'description', 'meta_title', 'meta_description',
|
||||
'icon', 'is_published', 'published_at', 'unpublish_at', 'is_featured', 'position',
|
||||
])]
|
||||
class Service extends Model
|
||||
{
|
||||
/** @use HasFactory<ServiceFactory> */
|
||||
use BumpsContentVersion, HasContentViews, HasFactory, HasPublicationWindow, HasReviews, HasRevisions, HasTranslations, RecordsSlugChanges, SoftDeletes;
|
||||
|
||||
/** @var array<int, string> */
|
||||
public array $translatable = [
|
||||
'title', 'slug', 'tagline', 'description', 'meta_title', 'meta_description',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_published' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'unpublish_at' => 'datetime',
|
||||
'is_featured' => 'boolean',
|
||||
'position' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the site is showing this right now.
|
||||
*/
|
||||
public function isPublishedNow(): bool
|
||||
{
|
||||
return $this->is_published
|
||||
&& ! $this->isScheduled()
|
||||
&& ! $this->hasExpired();
|
||||
}
|
||||
|
||||
/**
|
||||
* The `site.paths` key this model publishes under, so a slug change knows
|
||||
* which URL it just broke.
|
||||
*/
|
||||
public function publicPathType(): string
|
||||
{
|
||||
return 'service';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<Project, $this>
|
||||
*/
|
||||
public function projects(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Project::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<Technology, $this>
|
||||
*/
|
||||
public function technologies(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Technology::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Testimonial, $this>
|
||||
*/
|
||||
public function testimonials(): HasMany
|
||||
{
|
||||
return $this->hasMany(Testimonial::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<$this> $query
|
||||
* @return Builder<$this>
|
||||
*/
|
||||
public function scopePublished(Builder $query): Builder
|
||||
{
|
||||
return $query
|
||||
->where('is_published', true)
|
||||
// The same window as pages and projects, enforced in one place so
|
||||
// nothing that reads published services has to remember it.
|
||||
->where(fn (Builder $q) => $q
|
||||
->whereNull('published_at')
|
||||
->orWhere('published_at', '<=', now()))
|
||||
->where(fn (Builder $q) => $q
|
||||
->whereNull('unpublish_at')
|
||||
->orWhere('unpublish_at', '>', now()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<$this> $query
|
||||
* @return Builder<$this>
|
||||
*/
|
||||
public function scopeWhereSlug(Builder $query, string $slug, ?string $locale = null): Builder
|
||||
{
|
||||
$locale ??= app()->getLocale();
|
||||
|
||||
return $query->where("slug->{$locale}", $slug);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user