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:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles;
|
||||
|
||||
use App\Filament\Resources\Articles\Pages\CreateArticle;
|
||||
use App\Filament\Resources\Articles\Pages\EditArticle;
|
||||
use App\Filament\Resources\Articles\Pages\ListArticles;
|
||||
use App\Filament\Resources\Articles\Schemas\ArticleForm;
|
||||
use App\Filament\Resources\Articles\Tables\ArticlesTable;
|
||||
use App\Models\Article;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
use App\Filament\Concerns\HasTranslatedLabels;
|
||||
|
||||
class ArticleResource extends Resource
|
||||
{
|
||||
use HasTranslatedLabels;
|
||||
|
||||
protected static ?string $model = Article::class;
|
||||
|
||||
|
||||
|
||||
|
||||
protected static function navKey(): string
|
||||
{
|
||||
return 'articles';
|
||||
}
|
||||
|
||||
protected static function modelKey(): string
|
||||
{
|
||||
return 'article';
|
||||
}
|
||||
|
||||
protected static function groupKey(): string
|
||||
{
|
||||
return 'content';
|
||||
}
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentText;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return ArticleForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return ArticlesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListArticles::route('/'),
|
||||
'create' => CreateArticle::route('/create'),
|
||||
'edit' => EditArticle::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles\Pages;
|
||||
|
||||
use App\Domain\Plugin\Hook;
|
||||
use App\Filament\Resources\Articles\ArticleResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateArticle extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ArticleResource::class;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$filtered = Hook::filter('filament.article.mutate_before_save', $data, null);
|
||||
|
||||
return is_array($filtered) ? $filtered : $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
Hook::dispatch('filament.article.after_save', $this->record, $this->form->getState());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles\Pages;
|
||||
|
||||
use App\Domain\Ai\Jobs\OptimizeArticleContentJob;
|
||||
use App\Domain\Plugin\Hook;
|
||||
use App\Filament\Resources\Articles\ArticleResource;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditArticle extends EditRecord
|
||||
{
|
||||
protected static string $resource = ArticleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('aiOptimize')
|
||||
->label(__('admin.messages.ai_optimize'))
|
||||
->action(function (): void {
|
||||
OptimizeArticleContentJob::dispatch($this->record->getKey());
|
||||
Notification::make()
|
||||
->title(__('admin.messages.ai_optimize_queued'))
|
||||
->body(__('admin.messages.ai_optimize_queue_hint'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
DeleteAction::make(),
|
||||
...Hook::collect('filament.article.actions'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$filtered = Hook::filter('filament.article.mutate_before_fill', $data, $this->record);
|
||||
|
||||
return is_array($filtered) ? $filtered : $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$filtered = Hook::filter('filament.article.mutate_before_save', $data, $this->record);
|
||||
|
||||
return is_array($filtered) ? $filtered : $data;
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
Hook::dispatch('filament.article.after_save', $this->record, $this->form->getState());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles\Pages;
|
||||
|
||||
use App\Filament\Resources\Articles\ArticleResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListArticles extends ListRecords
|
||||
{
|
||||
protected static string $resource = ArticleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles\Schemas;
|
||||
|
||||
use App\Domain\Blog\ContentFormat;
|
||||
use App\Domain\Plugin\Hook;
|
||||
use App\Settings\GeneralSettings;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ArticleForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
$defaultFormat = ContentFormat::MARKDOWN;
|
||||
try {
|
||||
$defaultFormat = ContentFormat::normalize(app(GeneralSettings::class)->default_content_format, ContentFormat::MARKDOWN);
|
||||
} catch (\Throwable) {
|
||||
//
|
||||
}
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('category_id')
|
||||
->label(__('admin.fields.category'))
|
||||
->relationship('category', 'name')
|
||||
->required(),
|
||||
Select::make('user_id')
|
||||
->label(__('admin.fields.author'))
|
||||
->relationship('user', 'name')
|
||||
->required(),
|
||||
TextInput::make('title')
|
||||
->label(__('admin.fields.title'))
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
Select::make('content_format')
|
||||
->label(__('admin.fields.content_format'))
|
||||
->options([
|
||||
ContentFormat::MARKDOWN => __('admin.options.markdown_recommended'),
|
||||
ContentFormat::HTML => __('admin.options.html_legacy'),
|
||||
])
|
||||
->default($defaultFormat)
|
||||
->required()
|
||||
->live()
|
||||
->helperText(__('admin.helpers.article_content')),
|
||||
Textarea::make('content')
|
||||
->label(fn (Get $get): string => $get('content_format') === ContentFormat::MARKDOWN
|
||||
? __('admin.fields.content_markdown')
|
||||
: __('admin.fields.content_html'))
|
||||
->required()
|
||||
->rows(18)
|
||||
->columnSpanFull(),
|
||||
TextInput::make('description')
|
||||
->label(__('admin.fields.description')),
|
||||
TextInput::make('keywords')
|
||||
->label(__('admin.fields.keywords')),
|
||||
TextInput::make('slug')
|
||||
->label(__('admin.fields.slug')),
|
||||
DateTimePicker::make('published_at')
|
||||
->label(__('admin.fields.published_at'))
|
||||
->default(now()),
|
||||
Toggle::make('stick')
|
||||
->label(__('admin.fields.stick'))
|
||||
->default(false),
|
||||
Toggle::make('visible')
|
||||
->label(__('admin.fields.visible'))
|
||||
->default(true),
|
||||
Toggle::make('close_comment')
|
||||
->label(__('admin.fields.close_comment'))
|
||||
->default(false),
|
||||
TextInput::make('read_password')
|
||||
->label(__('admin.fields.read_password'))
|
||||
->password(),
|
||||
Textarea::make('ai_summary')
|
||||
->label(__('admin.fields.ai_summary'))
|
||||
->columnSpanFull(),
|
||||
...Hook::collect('filament.article.form'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles\Tables;
|
||||
|
||||
use App\Domain\Plugin\Hook;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ArticlesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('category.name')
|
||||
->label(__('admin.fields.category'))
|
||||
->searchable(),
|
||||
TextColumn::make('user.name')
|
||||
->label(__('admin.fields.author'))
|
||||
->searchable(),
|
||||
TextColumn::make('title')
|
||||
->label(__('admin.fields.title'))
|
||||
->searchable(),
|
||||
TextColumn::make('description')
|
||||
->label(__('admin.fields.description'))
|
||||
->searchable(),
|
||||
TextColumn::make('keywords')
|
||||
->label(__('admin.fields.keywords'))
|
||||
->searchable(),
|
||||
TextColumn::make('published_at')
|
||||
->label(__('admin.fields.published_at'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
TextColumn::make('views')
|
||||
->label(__('admin.fields.views'))
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('comments_count')
|
||||
->label(__('admin.fields.comments_count'))
|
||||
->numeric()
|
||||
->sortable(),
|
||||
IconColumn::make('stick')
|
||||
->label(__('admin.fields.stick'))
|
||||
->boolean(),
|
||||
IconColumn::make('visible')
|
||||
->label(__('admin.fields.visible'))
|
||||
->boolean(),
|
||||
IconColumn::make('close_comment')
|
||||
->label(__('admin.fields.close_comment'))
|
||||
->boolean(),
|
||||
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),
|
||||
TextColumn::make('slug')
|
||||
->label(__('admin.fields.slug'))
|
||||
->searchable(),
|
||||
TextColumn::make('content_format')
|
||||
->label(__('admin.fields.content_format'))
|
||||
->searchable(),
|
||||
...Hook::collect('filament.article.table.columns'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
...Hook::collect('filament.article.actions'),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user