Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Content Resource in Filament CMS #164

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 52 additions & 44 deletions app/Filament/App/Resources/ContentResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@

<?php

namespace App\Filament\App\Resources;

use App\Filament\App\Resources\ContentResource\Pages;
use App\Models\Content;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\BooleanColumn;
use Filament\Tables\Columns\ImageColumn;

class ContentResource extends Resource
{
protected static ?string $model = Content::class;

protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static ?string $navigationLabel = 'Content';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('content_title')
->required()
->maxLength(255),
Forms\Components\Select::make('author_id')
->relationship('author', 'author_name')
->required(),
Forms\Components\Select::make('category_id')
->relationship('category', 'content_category_name')
->required(),
Forms\Components\RichEditor::make('content_body')
->required(),
Forms\Components\TextInput::make('meta_title')
->maxLength(255),
Forms\Components\Textarea::make('meta_description')
->maxLength(65535),
Forms\Components\Toggle::make('is_featured')
->required(),
Forms\Components\DateTimePicker::make('published_at'),
Forms\Components\Select::make('content_status')
->options([
'draft' => 'Draft',
'published' => 'Published',
'archived' => 'Archived',
]),
Forms\Components\FileUpload::make('featured_image_url')
Expand All @@ -24,11 +73,11 @@ public static function table(Table $table): Table
->label('Author')
->searchable()
->sortable(),
BelongsToColumn::make('category.content_category_name')
TextColumn::make('category.content_category_name')
->label('Category')
->searchable()
->sortable(),
BadgeColumn::make('content_status')
Tables\Columns\BadgeColumn::make('content_status')
->label('Content Status')
->colors([
'draft' => 'warning',
Expand All @@ -49,9 +98,7 @@ public static function table(Table $table): Table
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
Tables\Actions\DeleteBulkAction::make(),
]);
}

Expand All @@ -70,43 +117,4 @@ public static function getPages(): array
'edit' => Pages\EditContent::route('/{record}/edit'),
];
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('content_title')
->required()
->maxLength(255),
Forms\Components\Select::make('author_id')
->relationship('author', 'author_name')
->required(),
Forms\Components\Select::make('category_id')
->relationship('category', 'content_category_name')
->required(),
Forms\Components\RichEditor::make('content_body')
->required(),
Forms\Components\TextInput::make('meta_title')
->maxLength(255),
Forms\Components\Textarea::make('meta_description')
->maxLength(65535),
Forms\Components\Toggle::make('is_featured')
->required(),
Forms\Components\DateTimePicker::make('published_at'),
Forms\Components\Select::make('content_status')
->options([
'draft' => 'Draft',
'published' => 'Published',
'archived' => 'Archived',
]),
Forms\Components\FileUpload::make('featured_image_url')
->image()
->directory('content-images')
->label('Featured Image'),
Forms\Components\TagsInput::make('tag')
->label('Tags')
->separator(',')
->relationship('tag', 'tag_name'),
]);
}
}
Loading