Skip to content

Commit

Permalink
Merge pull request #164 from liberu-cms/sweep/Refactor-Content-Resour…
Browse files Browse the repository at this point in the history
…ce-in-Filament-CMS

Refactor Content Resource in Filament CMS
  • Loading branch information
curtisdelicata authored Jul 20, 2024
2 parents 5039ac6 + 2afd1fb commit 9142c9f
Showing 1 changed file with 52 additions and 44 deletions.
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'),
]);
}
}

0 comments on commit 9142c9f

Please sign in to comment.