Add all files
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\KnowledgeBase\Admin\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
use Paymenter\Extensions\Others\KnowledgeBase\Admin\Resources\KnowledgeBaseResource\Pages;
|
||||
use Paymenter\Extensions\Others\KnowledgeBase\Models\Article;
|
||||
|
||||
class KnowledgeBaseResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Article::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-m-academic-cap';
|
||||
|
||||
protected static ?string $navigationGroup = 'Documentation';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('category_id')
|
||||
->label('Category')
|
||||
->relationship('category', 'name')
|
||||
->searchable()
|
||||
->required()
|
||||
->createOptionForm([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('slug')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\Textarea::make('description'),
|
||||
])
|
||||
->placeholder('Select a category'),
|
||||
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label('Title')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
|
||||
if (($get('slug') ?? '') !== Str::slug($old)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$set('slug', Str::slug($state));
|
||||
})
|
||||
->placeholder('Fill in the name for your article'),
|
||||
|
||||
Forms\Components\TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Fill in the name for your article'),
|
||||
|
||||
Forms\Components\TextInput::make('description')
|
||||
->label('Description')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Small description'),
|
||||
|
||||
Forms\Components\DateTimePicker::make('published_at')
|
||||
->label('Published at')
|
||||
->required()
|
||||
->placeholder('Date and time of publishment'),
|
||||
|
||||
Forms\Components\Toggle::make('is_active')
|
||||
->label('Published')
|
||||
->default(false),
|
||||
|
||||
Forms\Components\RichEditor::make('content')
|
||||
->columnSpanFull()
|
||||
->label('Content')
|
||||
->required()
|
||||
->placeholder('Enter the content of the article'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('category.name')
|
||||
->label('Category')
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('published_at')
|
||||
->searchable()
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\IconColumn::make('is_active')
|
||||
->label('Published')
|
||||
->boolean()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListKnowledgeBase::route('/'),
|
||||
'create' => Pages\CreateKnowledgeBase::route('/create'),
|
||||
'edit' => Pages\EditKnowledgeBase::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user