Add Blog module to Citrus Platform: Created Blog resource with CRUD pages, schemas, and models. Implemented localization for English and Turkish, ensuring consistent user experience. Added migrations for blog categories, posts, and comments, including soft delete functionality. Enhanced table and form structures for better organization and usability.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Blogs;
|
||||
|
||||
use App\Filament\Admin\Resources\Blogs\Pages\CreateBlog;
|
||||
use App\Filament\Admin\Resources\Blogs\Pages\EditBlog;
|
||||
use App\Filament\Admin\Resources\Blogs\Pages\ListBlogs;
|
||||
use App\Filament\Admin\Resources\Blogs\Schemas\BlogForm;
|
||||
use App\Filament\Admin\Resources\Blogs\Tables\BlogsTable;
|
||||
use App\Models\Blog;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class BlogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Blog::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentText;
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('blog.navigation_label');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('blog.model_label');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('blog.plural_model_label');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return BlogForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return BlogsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListBlogs::route('/'),
|
||||
'create' => CreateBlog::route('/create'),
|
||||
'edit' => EditBlog::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Blogs\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\Blogs\BlogResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateBlog extends CreateRecord
|
||||
{
|
||||
protected static string $resource = BlogResource::class;
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('blog.create');
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getCreatedNotificationTitle(): ?string
|
||||
{
|
||||
return __('blog.created_successfully');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Blogs\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\Blogs\BlogResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditBlog extends EditRecord
|
||||
{
|
||||
protected static string $resource = BlogResource::class;
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('blog.edit');
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make()
|
||||
->label(__('blog.delete')),
|
||||
RestoreAction::make()
|
||||
->label(__('blog.restore')),
|
||||
ForceDeleteAction::make()
|
||||
->label(__('blog.force_delete')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getSavedNotificationTitle(): ?string
|
||||
{
|
||||
return __('blog.updated_successfully');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Blogs\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\Blogs\BlogResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListBlogs extends ListRecords
|
||||
{
|
||||
protected static string $resource = BlogResource::class;
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('blog.title');
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label(__('blog.create')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Blogs\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TagsInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class BlogForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->schema([
|
||||
// Sol kolon - Ana içerik (2 sütun genişliğinde)
|
||||
Section::make(__('blog.content_section'))
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label(__('blog.title_field'))
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (string $operation, $state, callable $set) {
|
||||
if ($operation !== 'create') {
|
||||
return;
|
||||
}
|
||||
$set('slug', \Str::slug($state));
|
||||
}),
|
||||
|
||||
TextInput::make('slug')
|
||||
->label(__('blog.slug_field'))
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true)
|
||||
->rules(['alpha_dash'])
|
||||
->helperText(__('blog.slug_helper')),
|
||||
|
||||
RichEditor::make('content')
|
||||
->label(__('blog.content_field'))
|
||||
->required()
|
||||
->fileAttachmentsDisk('public')
|
||||
->fileAttachmentsDirectory('blogs')
|
||||
->fileAttachmentsVisibility('public')
|
||||
->columnSpanFull(),
|
||||
|
||||
Textarea::make('excerpt')
|
||||
->label(__('blog.excerpt_field'))
|
||||
->rows(3)
|
||||
->maxLength(500)
|
||||
->helperText(__('blog.excerpt_helper'))
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columnSpan(2)
|
||||
->collapsible(false),
|
||||
|
||||
// Sağ kolon - Metadata ve öne çıkan görsel (1 sütun genişliğinde)
|
||||
Section::make(__('blog.settings_section'))
|
||||
->schema([
|
||||
FileUpload::make('featured_image')
|
||||
->label(__('blog.featured_image_field'))
|
||||
->image()
|
||||
->disk('public')
|
||||
->directory('blogs/featured')
|
||||
->visibility('public')
|
||||
->imageEditor()
|
||||
->imageEditorAspectRatios([
|
||||
'16:9',
|
||||
'4:3',
|
||||
'1:1',
|
||||
])
|
||||
->helperText(__('blog.featured_image_helper'))
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('author_id')
|
||||
->label(__('blog.author_field'))
|
||||
->relationship('author', 'name')
|
||||
->default(auth()->id())
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('category_id')
|
||||
->label(__('blog.category_field'))
|
||||
->relationship('category', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->helperText(__('blog.category_helper'))
|
||||
->columnSpanFull(),
|
||||
|
||||
TagsInput::make('tags')
|
||||
->label(__('blog.tags_field'))
|
||||
->helperText(__('blog.tags_helper'))
|
||||
->columnSpanFull(),
|
||||
|
||||
DateTimePicker::make('published_at')
|
||||
->label(__('blog.published_at_field'))
|
||||
->displayFormat('d.m.Y H:i')
|
||||
->helperText(__('blog.published_at_helper'))
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('status')
|
||||
->label(__('blog.status_field'))
|
||||
->options([
|
||||
'draft' => __('blog.status_draft'),
|
||||
'published' => __('blog.status_published'),
|
||||
'archived' => __('blog.status_archived'),
|
||||
])
|
||||
->default('draft')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
|
||||
Checkbox::make('is_featured')
|
||||
->label(__('blog.is_featured_field'))
|
||||
->helperText(__('blog.is_featured_helper'))
|
||||
->columnSpanFull(),
|
||||
|
||||
Checkbox::make('allow_comments')
|
||||
->label(__('blog.allow_comments_field'))
|
||||
->default(true)
|
||||
->helperText(__('blog.allow_comments_helper'))
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columnSpan(1)
|
||||
->collapsible(false),
|
||||
|
||||
// Alt kısım - SEO ayarları (tam genişlik)
|
||||
Section::make(__('blog.seo_section'))
|
||||
->schema([
|
||||
TextInput::make('meta_title')
|
||||
->label(__('blog.meta_title_field'))
|
||||
->maxLength(60)
|
||||
->helperText(__('blog.meta_title_helper')),
|
||||
|
||||
Textarea::make('meta_description')
|
||||
->label(__('blog.meta_description_field'))
|
||||
->rows(3)
|
||||
->maxLength(160)
|
||||
->helperText(__('blog.meta_description_helper'))
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2)
|
||||
->columnSpanFull()
|
||||
->collapsible(true)
|
||||
->collapsed(true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Blogs\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BlogsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
ImageColumn::make('featured_image')
|
||||
->label(__('blog.featured_image_field'))
|
||||
->disk('public')
|
||||
->square()
|
||||
->size(60),
|
||||
|
||||
TextColumn::make('title')
|
||||
->label(__('blog.table_title'))
|
||||
->searchable()
|
||||
->sortable()
|
||||
->limit(50),
|
||||
|
||||
TextColumn::make('slug')
|
||||
->label(__('blog.table_slug'))
|
||||
->searchable()
|
||||
->sortable()
|
||||
->limit(30),
|
||||
|
||||
TextColumn::make('status')
|
||||
->label(__('blog.table_status'))
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'draft' => 'gray',
|
||||
'published' => 'success',
|
||||
'archived' => 'warning',
|
||||
})
|
||||
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
'draft' => __('blog.status_draft'),
|
||||
'published' => __('blog.status_published'),
|
||||
'archived' => __('blog.status_archived'),
|
||||
}),
|
||||
|
||||
TextColumn::make('author.name')
|
||||
->label(__('blog.table_author'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('category.name')
|
||||
->label(__('blog.table_category'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('published_at')
|
||||
->label(__('blog.table_published_at'))
|
||||
->dateTime('d.m.Y H:i')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('view_count')
|
||||
->label(__('blog.table_view_count'))
|
||||
->sortable()
|
||||
->alignCenter(),
|
||||
|
||||
ToggleColumn::make('is_featured')
|
||||
->label(__('blog.is_featured_field'))
|
||||
->alignCenter(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label(__('blog.table_created_at'))
|
||||
->dateTime('d.m.Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
TextColumn::make('updated_at')
|
||||
->label(__('blog.table_updated_at'))
|
||||
->dateTime('d.m.Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->label(__('blog.status_field'))
|
||||
->options([
|
||||
'draft' => __('blog.status_draft'),
|
||||
'published' => __('blog.status_published'),
|
||||
'archived' => __('blog.status_archived'),
|
||||
]),
|
||||
|
||||
SelectFilter::make('category_id')
|
||||
->label(__('blog.category_field'))
|
||||
->relationship('category', 'name'),
|
||||
|
||||
TernaryFilter::make('is_featured')
|
||||
->label(__('blog.is_featured_field')),
|
||||
|
||||
TernaryFilter::make('allow_comments')
|
||||
->label(__('blog.allow_comments_field')),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->label(__('blog.edit')),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make()
|
||||
->label(__('blog.delete')),
|
||||
RestoreBulkAction::make()
|
||||
->label(__('blog.restore')),
|
||||
ForceDeleteBulkAction::make()
|
||||
->label(__('blog.force_delete')),
|
||||
]),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user