Initial baseline: LaraBlog core with plugin commerce surface.

Captures the current working tree after theme slots, ArticleAccess, and the payment / paid-content plugins so subsequent work has a reviewable git history.
This commit is contained in:
ak
2026-08-12 01:15:38 +08:00
commit 263b98b218
337 changed files with 31393 additions and 0 deletions
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Attachments;
use App\Filament\Resources\Attachments\Pages\CreateAttachment;
use App\Filament\Resources\Attachments\Pages\EditAttachment;
use App\Filament\Resources\Attachments\Pages\ListAttachments;
use App\Filament\Resources\Attachments\Schemas\AttachmentForm;
use App\Filament\Resources\Attachments\Tables\AttachmentsTable;
use App\Models\Attachment;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use App\Filament\Concerns\HasTranslatedLabels;
class AttachmentResource extends Resource
{
use HasTranslatedLabels;
protected static ?string $model = Attachment::class;
protected static function navKey(): string
{
return 'attachments';
}
protected static function modelKey(): string
{
return 'attachment';
}
protected static function groupKey(): string
{
return 'content';
}
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
public static function form(Schema $schema): Schema
{
return AttachmentForm::configure($schema);
}
public static function table(Table $table): Table
{
return AttachmentsTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListAttachments::route('/'),
'create' => CreateAttachment::route('/create'),
'edit' => EditAttachment::route('/{record}/edit'),
];
}
}
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Attachments\Pages;
use App\Filament\Resources\Attachments\AttachmentResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Storage;
class CreateAttachment extends CreateRecord
{
protected static string $resource = AttachmentResource::class;
/**
* @param array<string, mixed> $data
* @return array<string, mixed>
*/
protected function mutateFormDataBeforeCreate(array $data): array
{
$disk = config('larablog.attachments_disk', 'attachments');
$path = $data['upload'] ?? null;
unset($data['upload']);
if (! is_string($path) || $path === '') {
throw new \InvalidArgumentException(__('admin.messages.upload_required'));
}
$storage = Storage::disk($disk);
$mime = method_exists($storage, 'mimeType') ? ($storage->mimeType($path) ?: null) : null;
$allowed = config('larablog.allowed_attachment_mimes', []);
if (is_string($mime) && $allowed !== [] && ! in_array($mime, $allowed, true)) {
$storage->delete($path);
throw new \InvalidArgumentException(__('admin.messages.mime_not_allowed', ['mime' => $mime]));
}
$data['disk'] = $disk;
$data['path'] = $path;
$data['filename'] = $data['filename'] ?: basename($path);
$data['mime'] = $mime;
$data['size'] = $storage->size($path) ?: 0;
$data['checksum'] = hash('sha256', (string) $storage->get($path));
$data['synced_at'] = now();
$data['visibility'] = $data['visibility'] ?? 'public';
$data['downloads'] = (int) ($data['downloads'] ?? 0);
return $data;
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Attachments\Pages;
use App\Domain\Media\AttachmentStorageService;
use App\Filament\Resources\Attachments\AttachmentResource;
use App\Models\Attachment;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditAttachment extends EditRecord
{
protected static string $resource = AttachmentResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make()
->before(function (Attachment $record, AttachmentStorageService $storage): void {
$storage->deleteFromDisk($record);
}),
];
}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Attachments\Pages;
use App\Filament\Resources\Attachments\AttachmentResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListAttachments extends ListRecords
{
protected static string $resource = AttachmentResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Attachments\Schemas;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
class AttachmentForm
{
public static function configure(Schema $schema): Schema
{
$disk = config('larablog.attachments_disk', 'attachments');
$mimes = config('larablog.allowed_attachment_mimes', []);
return $schema
->components([
Select::make('article_id')
->label(__('admin.fields.article'))
->relationship('article', 'title')
->searchable()
->preload(),
FileUpload::make('upload')
->label(__('admin.fields.upload'))
->disk($disk)
->directory(fn (): string => 'uploads/'.now()->format('Y/m'))
->visibility('public')
->acceptedFileTypes($mimes)
->maxSize(20480)
->required(fn (string $operation): bool => $operation === 'create')
->dehydrated(fn ($state): bool => filled($state))
->helperText(__('admin.helpers.attachment_upload')),
TextInput::make('filename')
->label(__('admin.fields.filename'))
->maxLength(255),
TextInput::make('visibility')
->label(__('admin.fields.visibility'))
->default('public')
->required(),
TextInput::make('legacy_filepath')
->label(__('admin.fields.legacy_filepath'))
->maxLength(255),
TextInput::make('downloads')
->label(__('admin.fields.downloads'))
->numeric()
->default(0)
->disabled()
->dehydrated(),
]);
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Attachments\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class AttachmentsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('article.title')
->label(__('admin.fields.article'))
->searchable(),
TextColumn::make('disk')
->label(__('admin.fields.disk'))
->searchable(),
TextColumn::make('path')
->label(__('admin.fields.path'))
->searchable(),
TextColumn::make('thumb_path')
->label(__('admin.fields.thumb_path'))
->searchable(),
TextColumn::make('filename')
->label(__('admin.fields.filename'))
->searchable(),
TextColumn::make('mime')
->label(__('admin.fields.mime'))
->searchable(),
TextColumn::make('size')
->label(__('admin.fields.size'))
->numeric()
->sortable(),
TextColumn::make('checksum')
->label(__('admin.fields.checksum'))
->searchable(),
TextColumn::make('visibility')
->label(__('admin.fields.visibility'))
->searchable(),
TextColumn::make('legacy_filepath')
->label(__('admin.fields.legacy_filepath'))
->searchable(),
TextColumn::make('synced_at')
->label(__('admin.fields.synced_at'))
->dateTime()
->sortable(),
TextColumn::make('downloads')
->label(__('admin.fields.downloads'))
->numeric()
->sortable(),
TextColumn::make('created_at')
->label(__('admin.fields.created_at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->label(__('admin.fields.updated_at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}