Admin Panel
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-09-29 14:57:37 +07:00
parent 04fbddba13
commit 8c6dad2a31
94 changed files with 4864 additions and 1151 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Models;
use App\Enums\ConsultationStatus;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
/**
* A consultation request submitted through one of the site's forms.
*
* @property int $id
* @property string $source
* @property string $name
* @property string|null $company
* @property string|null $job_title
* @property string $email
* @property string $phone
* @property string|null $industry
* @property string|null $service
* @property string|null $timeline
* @property string|null $details
* @property bool $nda_agreed
* @property string $locale
* @property ConsultationStatus $status
* @property string|null $admin_notes
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
#[Fillable([
'source', 'name', 'company', 'job_title', 'email', 'phone', 'industry',
'service', 'timeline', 'details', 'nda_agreed', 'locale', 'status', 'admin_notes',
])]
class Consultation extends Model
{
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'nda_agreed' => 'boolean',
'status' => ConsultationStatus::class,
];
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use App\Support\SiteInfo;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $name
* @property string $icon
* @property string $building
* @property string $street
* @property string $area
* @property string $city
* @property string $district
* @property string $phone
* @property string|null $maps_url
* @property int $sort_order
*/
#[Fillable(['name', 'icon', 'building', 'street', 'area', 'city', 'district', 'phone', 'maps_url', 'sort_order'])]
class Office extends Model
{
protected static function booted(): void
{
static::saved(fn () => SiteInfo::forget());
static::deleted(fn () => SiteInfo::forget());
}
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'sort_order' => 'integer',
];
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Models;
use App\Enums\ProjectProgram;
use App\Enums\ProjectSector;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
/**
* An entry in PAJ's IT project track record (the site's portfolio).
*
* @property int $id
* @property string $title
* @property string $client
* @property int $year
* @property ProjectSector $sector
* @property ProjectProgram|null $program
* @property string|null $scope
*/
#[Fillable(['title', 'client', 'year', 'sector', 'program', 'scope'])]
class Project extends Model
{
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'year' => 'integer',
'sector' => ProjectSector::class,
'program' => ProjectProgram::class,
];
}
/**
* Newest projects first, as the site lists them.
*
* @param Builder<Project> $query
*/
public function scopeLatestFirst(Builder $query): void
{
$query->orderByDesc('year')->orderBy('id');
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use App\Support\SiteInfo;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
/**
* Key/value store for editable site settings (e.g. contact details).
*
* @property int $id
* @property string $key
* @property array<string, mixed> $value
*/
#[Fillable(['key', 'value'])]
class SiteSetting extends Model
{
protected static function booted(): void
{
static::saved(fn () => SiteInfo::forget());
}
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'value' => 'array',
];
}
/**
* @param array<string, mixed> $default
* @return array<string, mixed>
*/
public static function get(string $key, array $default = []): array
{
return static::query()->where('key', $key)->first()?->value ?? $default;
}
/**
* @param array<string, mixed> $value
*/
public static function put(string $key, array $value): void
{
static::query()->updateOrCreate(['key' => $key], ['value' => $value]);
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
/**
* A client testimonial, written in both site languages.
*
* @property int $id
* @property string $quote_id
* @property string $quote_en
* @property string $role_id
* @property string $role_en
* @property string $organization_id
* @property string $organization_en
* @property bool $is_published
* @property int $sort_order
*/
#[Fillable([
'quote_id', 'quote_en', 'role_id', 'role_en',
'organization_id', 'organization_en', 'is_published', 'sort_order',
])]
class Testimonial extends Model
{
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'is_published' => 'boolean',
'sort_order' => 'integer',
];
}
/**
* @param Builder<Testimonial> $query
*/
public function scopePublished(Builder $query): void
{
$query->where('is_published', true)->orderBy('sort_order')->orderBy('id');
}
/**
* The testimonial in the visitor's language.
*
* @return array{id: int, quote: string, role: string, organization: string}
*/
public function localized(string $locale): array
{
$suffix = $locale === 'en' ? 'en' : 'id';
return [
'id' => $this->id,
'quote' => $this->{"quote_{$suffix}"},
'role' => $this->{"role_{$suffix}"},
'organization' => $this->{"organization_{$suffix}"},
];
}
}
+12 -1
View File
@@ -3,6 +3,7 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Enums\UserRole;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
@@ -18,6 +19,7 @@ use Laravel\Fortify\TwoFactorAuthenticatable;
* @property int $id
* @property string $name
* @property string $email
* @property UserRole $role
* @property Carbon|null $email_verified_at
* @property string $password
* @property string|null $two_factor_secret
@@ -27,7 +29,7 @@ use Laravel\Fortify\TwoFactorAuthenticatable;
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
#[Fillable(['name', 'email', 'password'])]
#[Fillable(['name', 'email', 'role', 'password'])]
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
class User extends Authenticatable implements PasskeyUser
{
@@ -44,7 +46,16 @@ class User extends Authenticatable implements PasskeyUser
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'role' => UserRole::class,
'two_factor_confirmed_at' => 'datetime',
];
}
/**
* Admins manage users on top of everything an editor can do.
*/
public function isAdmin(): bool
{
return $this->role === UserRole::Admin;
}
}